import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.concurrent.TimeUnit;
public class Installer {
JFrame frame = new JFrame("Installer");
JLabel dir = new JLabel();
JPanel dirPanel = new JPanel();
JButton selectButton = new JButton("Browse");
JButton okButton = new JButton("Confirm");
JPanel okPanel = new JPanel();
JFileChooser fc = new JFileChooser(System.getProperty("user.home") + "//Downloads");
String directoryRaw;
String directory;
JProgressBar loading = new JProgressBar(0, 100);
JFrame frame2 = new JFrame("Installing...");
public static void main(String[] args) {
Installer m = new Installer();
m.frame.setSize(500, 120);
m.frame.setLocationRelativeTo(null);
m.frame.setVisible(true);
m.dir.setText("Select A Directory: ");
m.dirPanel.add(m.dir);
m.dirPanel.add(m.selectButton);
m.okButton.setEnabled(false);
m.frame.add(m.dirPanel, BorderLayout.NORTH);
m.okPanel.add(m.okButton);
m.frame.add(m.okPanel, BorderLayout.SOUTH);
m.fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
m.selectButton.addActionListener(new ActionListener() {
// Override the actionPerformed() method
public void actionPerformed(ActionEvent e){
//Handle open button action.
if (e.getSource() == m.selectButton) {
int returnVal = m.fc.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = m.fc.getSelectedFile();
//This is where a real application would open the file.
m.directoryRaw = file.getAbsolutePath();
System.out.println(m.directoryRaw);
m.dir.setText(file.getAbsolutePath() + " ");
m.okButton.setEnabled(true);
} else {
m.dir.setText("Select A Directory: ");
}
}
}
});
m.okButton.addActionListener(new ActionListener() {
// Override the actionPerformed() method
public void actionPerformed(ActionEvent e){
m.Install();
}
});
}
public void Install() {
directory = directoryRaw.replace("\\","\\\\");
frame2.setSize(500, 120);
frame2.setLocationRelativeTo(null);
frame2.setVisible(true);
loading.setBounds(50, 30, 200, 30);
loading.setValue(0);
loading.setStringPainted(true);
loading.setBackground(new Color(0, 51, 51));
loading.setVisible(true);
frame2.add(loading);
for(int i = 0; i < 100; i++) {
loading.setString(Integer.toString(loading.getValue()+1) + "%");
loading.setValue(loading.getValue()+1);
if(loading.getValue()+1 < 100) {
System.out.println(Integer.toString(loading.getValue()+1) + "%");
}
try{
TimeUnit.MILLISECONDS.sleep(100);
} catch(Exception e) {
}
}
try {
File ttt = new File(directory + "\\TicTacToe.java");
if (ttt.createNewFile()) {
} else {
System.out.println("File already exists.");
}
} catch (IOException e) {
}
try {
FileWriter TTT = new FileWriter(directory + "\\TicTacToe.java");
TTT.write("import java.awt.*; \n import java.awt.event.*; \n import javax.swing.*; \n import java.lang.*; \n import java.util.*; \n import java.io.*; \n public class TicTacToe { \n int boardWidth = 600; \n int boardHeight = 650; \n JFrame frame = new JFrame(\"Tic-Tac-Toe\"); \n JLabel textLabel = new JLabel(); \n JPanel textPanel = new JPanel(); \n JPanel boardPanel = new JPanel(); \n JButton[][] board = new JButton[3][3]; \n String playerX = \"X\"; \n String playerO = \"O\"; \n String currentPlayer = playerX; \n boolean gameOver = false; \n int turns = 0; \n public static void main(String[] args) { \n TicTacToe m = new TicTacToe(); \n m.frame.setVisible(true); \n m.frame.setSize(m.boardWidth, m.boardHeight); \n m.frame.setLocationRelativeTo(null); \n m.frame.setResizable(false); \n m.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); \n m.frame.setLayout(new BorderLayout()); \n m.textLabel.setOpaque(true); \n m.textLabel.setBackground(new Color(100, 100, 100)); \n m.textLabel.setForeground(Color.white); \n m.textLabel.setFont(new Font(\"Arial\", Font.BOLD, 50)); \n m.textLabel.setHorizontalAlignment(JLabel.CENTER); \n m.textLabel.setText(\"Tic-Tac-Toe\"); \n m.textPanel.setLayout(new BorderLayout()); \n m.textPanel.add(m.textLabel); \n m.frame.add(m.textPanel, BorderLayout.NORTH); \n m.boardPanel.setLayout(new GridLayout(3, 3)); \n m.boardPanel.setBackground(new Color(100, 100, 100)); \n m.frame.add(m.boardPanel); \n for(int r = 0; r < 3; r++) { \n for(int c = 0; c < 3; c++) { \n JButton tile = new JButton(); \n m.board[r][c] = tile; \n m.boardPanel.add(tile); \n tile.setBackground(new Color(100, 100, 100)); \n tile.setForeground(Color.white); \n tile.setFont(new Font(\"Arial\", Font.BOLD, 120)); \n tile.setFocusable(false); \n tile.addActionListener(new ActionListener() { \n public void actionPerformed(ActionEvent e) { \n if(m.gameOver) return; \n JButton tile = (JButton) e.getSource(); \n if(tile.getText() == \"\") { \n tile.setText(m.currentPlayer); \n m.turns++; \n m.checkWinner(); \n if(!m.gameOver) { \n m.currentPlayer = m.currentPlayer == m.playerX ? m.playerO : m.playerX; \n m.textLabel.setText(m.currentPlayer + \"'s turn.\"); \n } \n } \n } \n }); \n } \n } \n } \n void checkWinner() { \n for(int r = 0; r < 3; r++) { \n if(board[r][0].getText() == \"\") continue; \n if(board[r][0].getText() == board[r][1].getText() && board[r][1].getText() == board[r][2].getText()) { \n for(int i = 0; i < 3; i++) { \n setWinner(board[r][i]); \n } \n gameOver = true; \n return; \n } \n } \n for(int c = 0; c < 3; c++) { \n if(board[0][c].getText() == \"\") continue; \n if(board[0][c].getText() == board[1][c].getText() && board[1][c].getText() == board[2][c].getText()) { \n for(int i = 0; i < 3; i++) { \n setWinner(board[i][c]); \n } \n gameOver = true; \n return; \n } \n } \n if(board[0][0].getText() == board[1][1].getText() && board[1][1].getText() == board[2][2].getText() && board[0][0].getText() != \"\") { \n for(int i = 0; i < 3; i++) { \n setWinner(board[i][i]); \n } \n gameOver = true; \n return; \n } \n if(board[0][2].getText() == board[1][1].getText() && board[1][1].getText() == board[2][0].getText() && board[0][2].getText() != \"\") { \n setWinner(board[0][2]); \n setWinner(board[1][1]); \n setWinner(board[2][0]); \n gameOver = true; \n return; \n } \n if(turns == 9) { \n for(int r = 0; r < 3; r++) { \n for(int c = 0; c < 3; c++) { \n setTie(board[r][c]); \n } \n } \n gameOver = true; \n } \n } \n void setWinner(JButton tile) { \n tile.setForeground(Color.green); \n tile.setBackground(new Color(127, 127, 127)); \n textLabel.setText(currentPlayer + \" is the winner!!!\"); \n frame.addMouseListener(new MouseListener() { \n public void mouseClicked(MouseEvent e) {} \n public void mousePressed(MouseEvent e) { \n resetGame(); \n } \n public void mouseReleased(MouseEvent e) {} \n public void mouseEntered(MouseEvent e) {} \n public void mouseExited(MouseEvent e) {} \n }); \n } \n void setTie(JButton tile) { \n tile.setForeground(Color.orange); \n tile.setBackground(new Color(127, 127, 127)); \n textLabel.setText(\"TIE!\"); \n frame.addMouseListener(new MouseListener() { \n public void mouseClicked(MouseEvent e) {} \n public void mousePressed(MouseEvent e) { \n resetGame(); \n } \n public void mouseReleased(MouseEvent e) {} \n public void mouseEntered(MouseEvent e) {} \n public void mouseExited(MouseEvent e) {} \n }); \n } \n void Wait(long waitTime) { \n long startTime = System.currentTimeMillis(); \n while(System.currentTimeMillis()-startTime < waitTime) {} \n return; \n } \n void resetGame() { \n for(int r = 0; r < 3; r++) { \n for(int c = 0; c < 3; c++) { \n board[r][c].setText(\"\"); \n board[r][c].setBackground(new Color(100, 100, 100)); \n board[r][c].setForeground(Color.white); \n } \n } \n textLabel.setText(\"X's turn.\"); \n turns = 0; \n currentPlayer = playerX; \n gameOver = false; \n } \n }");
TTT.close();
} catch(IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
System.exit(0);
}
}