Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.Box;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.JOptionPane;
- import javax.swing.JFrame;
- import java.sql.*;
- import javax.swing.JPanel;
- import javax.swing.SwingConstants;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- public class FrontScreen implements ActionListener
- {
- private static JRadioButton rb1, rb2, rb3;
- private static final JFrame f = new JFrame("Welcome to Ballon d'or , created by Darren Estcourt");
- private static JButton b;
- private static JPanel myFirstPanel;
- private static JLabel ballondor , trophylabel;
- private static String firstName , surname;
- public FrontScreen()
- {
- }
- public void CreateAndShowFrontScreen()
- {
- f.setExtendedState(JFrame.MAXIMIZED_BOTH);
- f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
- myFirstPanel = new JPanel();
- myFirstPanel.setBackground(Color.GREEN);
- f.add(myFirstPanel, BorderLayout.CENTER);
- ballondor = new JLabel("Ballon d'or");
- ballondor.setToolTipText("Ballon d'or tooltip");
- myFirstPanel.add(ballondor);
- Icon trophy = new ImageIcon(getClass().getResource("Ballondor.jpg"));
- trophylabel = new JLabel("Please choose an option, then click OK" , trophy, SwingConstants.RIGHT);
- trophylabel.setToolTipText("Trophy Label tooltip");
- myFirstPanel.add(trophylabel);
- rb1 = new JRadioButton("Start New Game");
- rb2 = new JRadioButton("Load Game");
- rb3 = new JRadioButton("Quit");
- Box box1 = Box.createVerticalBox();
- box1.add(rb1); // TEST VERTICAL RADIO BUTTONS !
- box1.add(rb2);
- box1.add(rb3);
- myFirstPanel.add(box1);
- ButtonGroup bg=new ButtonGroup();
- bg.add(rb1);
- bg.add(rb2);
- bg.add(rb3);
- b = new JButton("OK");
- myFirstPanel.add(b);
- b.addActionListener(this);
- f.addWindowListener(new WindowAdapter()
- {
- @Override public void windowClosing(WindowEvent e)
- {
- if(JOptionPane.showConfirmDialog(f, "Are you sure ?" , "Warning", JOptionPane.YES_NO_OPTION ) == JOptionPane.YES_OPTION)
- {
- f.setVisible(false);
- f.dispose();
- }
- else{
- }
- }
- });
- } // OUT OF SCOPE !!!!!!
- @Override public void actionPerformed(ActionEvent e)
- {
- if(rb1.isSelected())
- {
- myFirstPanel.setVisible(false);
- ManagerName panel = new ManagerName();
- f.add(panel);
- f.pack();
- panel.setVisible(true);
- }
- if(rb2.isSelected())
- {
- JOptionPane.showMessageDialog(f ,"Which saved game would you like to load?", "Load game", JOptionPane.QUESTION_MESSAGE);
- }
- if(rb3.isSelected())
- {
- System.exit(0);
- }
- }
- public static void main(String[] args) throws SQLException , ClassNotFoundException, InstantiationException, IllegalAccessException
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- FrontScreen test = new FrontScreen();
- test.CreateAndShowFrontScreen();
- f.pack();
- f.setVisible(true);
- }
- });
- Database passFirstNameObject = new Database(firstName , surname);
- passFirstNameObject.setFirstName(firstName);
- } // end main
- }
- ------------------------------------------------------------------------------
- import java.awt.Color;
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JLabel;
- import java.sql.*;
- /**
- *
- * @author Darren Estcourt
- */
- public class ManagerName extends JPanel implements ActionListener
- {
- private final JLabel firstNameLabel , surnameLabel;
- private final JButton confirmNames , quit;
- private String firstName , surname;
- private final JTextField myTextField , myTextField2;
- public ManagerName()
- {
- setBackground(Color.GREEN);
- firstNameLabel = new JLabel("Please enter your first name");
- add(firstNameLabel);
- myTextField = new JTextField(20); // or use 20 columns
- add(myTextField);
- myTextField.addActionListener(this);
- surnameLabel = new JLabel("Please enter your surname");
- add(surnameLabel);
- myTextField2 = new JTextField(20);
- add(myTextField2);
- myTextField2.addActionListener(this);
- confirmNames = new JButton("Submit Names");
- confirmNames.addActionListener(this);
- add(confirmNames);
- quit = new JButton("Quit");
- quit.addActionListener(this);
- add(quit);
- }
- @Override public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==confirmNames)
- {
- firstName = myTextField.getText();
- surname = myTextField2.getText();
- try{
- Database passFirstNameObject = new Database(firstName , surname);
- passFirstNameObject.setFirstName(firstName);
- passFirstNameObject.setSurname(surname);
- Database.databaseMethod(passFirstNameObject);
- }
- catch(SQLException i)
- {
- System.err.println("Got an exception! ");
- }
- catch(ClassNotFoundException a)
- {
- System.err.println("Got an exception! ");
- }
- catch(InstantiationException b)
- {
- System.err.println("Got an exception! ");
- }
- catch(IllegalAccessException c)
- {
- System.err.println("Got an exception! ");
- }
- JOptionPane.showMessageDialog(null, "Your name is : " + firstName + " " + surname);
- this.setVisible(false);
- NewGame callNewGamePanel = new NewGame();
- this.add(callNewGamePanel);
- callNewGamePanel.setVisible(true);
- }
- if(e.getSource()==quit)
- {
- System.exit(0);
- }
- }
- }
- ------------------------------------------------------------------------
- import java.awt.event.*;
- import javax.swing.*;
- import javax.swing.JOptionPane;
- import javax.swing.JLabel;
- import java.awt.Color;
- public class NewGame extends JPanel implements ActionListener
- {
- private final String[] premierLeagueClubs = {"Arsenal" , "Bournemouth" , "Burnley" , "Chelsea" , "Crystal Palace" ,
- "Everton" , "Hull City" , "Leicester City" , "Liverpool" , "Manchester United" , "Manchester City" , "Middlesborough" ,
- "Southampton" , "Stoke City", "Sunderland", "Swansea City", "Tottenham Hotspur" , "Watford" , "West Brom" , "West Ham"};
- private final JRadioButton[] rb = new JRadioButton[20];
- JButton confirmTeam , quit;
- String teamName;
- JLabel label1;
- public NewGame()
- {
- setBackground(Color.GREEN);
- label1 = new JLabel("Please choose a team");
- add(label1);
- for (int i = 0; i < premierLeagueClubs.length; i++)
- {
- rb[i] = new JRadioButton(premierLeagueClubs[i]);
- rb[i].setActionCommand(premierLeagueClubs[i]);
- }
- confirmTeam = new JButton("OK");
- confirmTeam.addActionListener(this);
- add(confirmTeam);
- for(int j=0; j < 20; j++)
- {
- add(rb[j]);
- }
- ButtonGroup bg=new ButtonGroup();
- int startvalueBG;
- int endvalueBG=19;
- for(startvalueBG=0; startvalueBG <= endvalueBG; startvalueBG++)
- {
- bg.add(rb[startvalueBG]);
- }
- quit = new JButton("Quit");
- quit.addActionListener(this);
- add(quit);
- }
- @Override public void actionPerformed(ActionEvent e)
- {
- if(e.getSource()==confirmTeam)
- {
- for(int i=0; i < 20; i++){
- if(rb[i].isSelected())
- {
- JOptionPane.showMessageDialog(null , "You chose:" + premierLeagueClubs[i]);
- }
- }
- if(e.getSource()==quit)
- {
- System.exit(0);
- }
- }
- }
- }
- ------------------------------------------------------------------------------
- import java.sql.*;
- public class Database
- {
- private String firstName , surname;
- public Database(String firstName , String surname)
- {
- this.firstName = firstName;
- this.surname = surname;
- }
- public void setFirstName(String firstName)
- {
- this.firstName = firstName;
- }
- public String getFirstName()
- {
- return firstName;
- }
- public void setSurname(String surname)
- {
- this.surname = surname;
- }
- public String getSurname()
- {
- return surname;
- }
- public static void databaseMethod(Database passFirstNameObject) throws SQLException , ClassNotFoundException, InstantiationException,IllegalAccessException
- {
- String myDriver = "com.mysql.jdbc.Driver";
- String myUrl = "jdbc:mysql://localhost:3306/ballondor?autoReconnect=true&useSSL=false";
- Connection connOne = DriverManager.getConnection(myUrl, "root", "Lucia290907");
- Connection connTwo = DriverManager.getConnection(myUrl, "root", "Lucia290907");
- Statement st1 = connOne.createStatement();
- Statement st2 = connTwo.createStatement();
- Class.forName(myDriver).newInstance();
- JOptionPane.showMessageDialog(null,"List of team names" ,TeamName, JOptionPane.QUESTION_MESSAGE);
- System.out.println("The first attempt :" + passFirstNameObject.getFirstName() + passFirstNameObject.getSurname());
- st2.executeUpdate("insert into managername (firstName,surname) values('"+passFirstNameObject.getFirstName()+"' , '"+passFirstNameObject.getSurname()+"')"); // UPDATING MYSQL DATABASE
- // } // end while loop
- st1.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement