I can't get my class TestTable to show in my class CrapsGame. I need some help! I really don't know where the issue is . Thanks in advance.
Code:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
/*
* This class displayed the craps game.
* It has a menu displayed all of the buttons
* and graphics needed to play the game.
*/
public class CrapsGame extends JPanel
{
private static final long serialVersionUID = 1L;
//Sets up the bank account
private static BankAccount account = new BankAccount(1000.00);
public static void main(String[] args) throws InterruptedException, LineUnavailableException, IOException, UnsupportedAudioFileException
{
//Starts splash screen
startSplash();
//Creates a Jframe
JFrame frame = new Menu();
//Adds a panel to the frame
JPanel layout = new JPanel();
//Sets the layout of the panel
layout.setLayout(new BorderLayout());
//Creates the table for game
//CreateTable table = new CreateTable();
layout.add(new TestTable());
//Adds the table to the frame in center
//layout.add(table, BorderLayout.CENTER);
layout.add(createFooter(), BorderLayout.SOUTH);
//Adds layout panel the JFrame
frame.add(layout);
frame.getContentPane();
//When program closed it terminates program execution
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Makes frame visible
frame.setVisible(true);
}//ends main
/*
* This method retrieves the SplashScreen class
* then it sets the timer for the screen and
* gets the song used as a wav file.
*/
private static void startSplash() throws InterruptedException, LineUnavailableException, IOException, UnsupportedAudioFileException
{
//Adds the splash screen
SplashScreen splash = new SplashScreen();
//Packs splash
splash.pack();
//Sets splash visible
splash.setVisible(true);
//Timer for how long splash is up
Thread.sleep(10000);
//Closes splash screen after duration
splash.dispose();
}
/*
* This method creates the footer footer for the game creating
* the bank account spot and also the roll button.
*/
public static Component createFooter()
{
//Creates a new JPanel
JPanel panel = new JPanel();
//Creates a JButton called roll
JButton roll = new JButton("roll");
//This listener creates two random die and saves their values
class RollListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int die1 = Roll.die1();
int die2 = Roll.die2();
System.out.println(die1 + die2);
}
}
//Creates the listener to add to button
RollListener listener = new RollListener();
//Adds listener to button
roll.addActionListener(listener);
//Sets where to place the button
roll.setBounds(450,665,110,30);
//Adds the button to panel
panel.add(roll);
//Creates a new JLabel
JLabel bankAccount = new JLabel("BALANCE: ");
//Sets the location of the label
bankAccount.setBounds(600, 665, 60, 30);
//Adds the label to the panel
panel.add(bankAccount);
//Creates a JTextField
JTextField bank2 = new JTextField(10);
//Sets location to put the JTextField
bank2.setBounds(670, 665, 80, 30);
//Sets the JTextField to uneditable
bank2.setEditable(false);
//sets BankAccount balance into a string
String answer = String.valueOf(account.getBalance());
//sets the string into the JTextField
bank2.setText(answer);
//Adds to the panel
panel.add(bank2);
//Returns panel
return panel;
}
}//ends class CrapsGame
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class TestTable extends JPanel implements ActionListener
{
private static final long serialVersionUID = 1L;
private static Die die;
protected JTextField box11;
protected JTextField box1;
protected JTextField box2;
protected JTextField box3;
protected JTextField box4;
protected JTextField box5;
protected JTextField box6;
protected JTextField box7;
protected JTextField box8;
protected JTextField box9;
protected JTextField box10;
protected JTextField box12;
protected JTextField box13;
protected JTextField box14;
protected JTextField box15;
protected JTextField box16;
protected JTextField box17;
protected JTextField box18;
protected JTextField box19;
protected JTextField box20;
protected JTextArea textArea;
protected JTextArea textArea1;
protected JTextArea textArea2;
protected JTextArea textArea3;
protected JTextArea textArea4;
protected JTextArea textArea5;
protected JTextArea textArea6;
protected JTextArea textArea7;
protected JTextArea textArea8;
protected JTextArea textArea9;
protected JTextArea textArea10;
protected JTextArea textArea11;
protected JTextArea textArea12;
protected JTextArea textArea13;
protected JTextArea textArea14;
protected JTextArea textArea15;
protected JTextArea textArea16;
protected JTextArea textArea17;
protected JTextArea textArea18;
protected JTextArea textArea19;
public TestTable()
{
BankAccount account = new BankAccount(1000.00);
System.out.println(account);
//Creates JFrame
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(null);
JLabel hard4 = new JLabel("HARD 4");
hard4.setBounds(285,50,70,20);
box11 = new JTextField(3);
box11.addActionListener(this);
box11.setBounds(280,70,50,20);
textArea = new JTextArea(5, 20);
textArea.setEditable(false);
textArea.setBounds(225,70,50,20);
panel.add(hard4);
panel.add(box11);
panel.add(textArea);
JLabel hard6 = new JLabel("HARD 6");
hard6.setBounds(340,50,70,20);
box12 = new JTextField(3);
box12.addActionListener(this);
box12.setBounds(335,70,50,20);
textArea1 = new JTextArea(5, 20);
textArea1.setEditable(false);
textArea1.setBounds(390,70,50,20);
panel.add(hard6);
panel.add(box12);
panel.add(textArea1);
JLabel hard8 = new JLabel("HARD 8");
hard8.setBounds(285,110,70,20);
box13 = new JTextField(3);
box13.addActionListener(this);
box13.setBounds(280,130,50,20);
textArea2 = new JTextArea(5, 20);
textArea2.setEditable(false);
textArea2.setBounds(225,130,50,20);
panel.add(hard8);
panel.add(box13);
panel.add(textArea2);
JLabel hard10 = new JLabel("HARD 10");
hard10.setBounds(336,110,70,20);
box14 = new JTextField(3);
box14.addActionListener(this);
box14.setBounds(335,130,50,20);
textArea3 = new JTextArea(5, 20);
textArea3.setEditable(false);
textArea3.setBounds(390,130,50,20);
panel.add(hard10);
panel.add(box14);
panel.add(textArea3);
JLabel world = new JLabel("WORLD");
world.setBounds(310,170,70,20);
box15 = new JTextField(3);
box15.addActionListener(this);
box15.setBounds(307,190,50,20);
textArea4 = new JTextArea(5, 20);
textArea4.setEditable(false);
textArea4.setBounds(252,190,50,20);
panel.add(world);
panel.add(box15);
panel.add(textArea4);
JLabel three = new JLabel("THREE");
three.setBounds(285,230,70,20);
box16 = new JTextField(3);
box16.addActionListener(this);
box16.setBounds(280,250,50,20);
textArea5 = new JTextArea(5, 20);
textArea5.setEditable(false);
textArea5.setBounds(225,250,50,20);
panel.add(three);
panel.add(box16);
panel.add(textArea5);
JLabel twelve = new JLabel("TWELVE");
twelve.setBounds(335,230,70,20);
box17 = new JTextField(3);
box17.addActionListener(this);
box17.setBounds(335,250,50,20);
textArea6 = new JTextArea(5, 20);
textArea6.setEditable(false);
textArea6.setBounds(390,250,50,20);
panel.add(twelve);
panel.add(box17);
panel.add(textArea6);
JLabel two = new JLabel("TWO");
two.setBounds(290,290,70,20);
box18 = new JTextField(3);
box18.addActionListener(this);
box18.setBounds(280,310,50,20);
textArea7 = new JTextArea(5, 20);
textArea7.setEditable(false);
textArea7.setBounds(225,310,50,20);
panel.add(two);
panel.add(box18);
panel.add(textArea7);
JLabel craps = new JLabel("ALL CRAPS");
craps.setBounds(300,350,100,20);
box20 = new JTextField(3);
box20.addActionListener(this);
box20.setBounds(305,370,50,20);
textArea8 = new JTextArea(5, 20);
textArea8.setEditable(false);
textArea8.setBounds(250,370,50,20);
panel.add(craps);
panel.add(box20);
panel.add(textArea8);
JLabel eleven = new JLabel("ELEVEN");
eleven.setBounds(338,290,70,20);
box19 = new JTextField(3);
box19.addActionListener(this);
box19.setBounds(335,310,50,20);
textArea9 = new JTextArea(5, 20);
textArea9.setEditable(false);
textArea9.setBounds(390,310,50,20);
panel.add(eleven);
panel.add(box19);
panel.add(textArea9);
JLabel label1 = new JLabel("4");
label1.setBounds(650,50,20,20);
box1 = new JTextField(3);
box1.addActionListener(this);
box1.setBounds(630,70,50,20);
textArea10 = new JTextArea(5, 20);
textArea10.setEditable(false);
textArea10.setBounds(630,95,50,20);
JLabel label2 = new JLabel("5");
label2.setBounds(705,50,20,20);
box2 = new JTextField(3);
box2.addActionListener(this);
box2.setBounds(685,70,50,20);
textArea11 = new JTextArea(5, 20);
textArea11.setEditable(false);
textArea11.setBounds(685,95,50,20);
JLabel label3 = new JLabel("6");
label3.setBounds(760,50,20,20);
box3 = new JTextField(3);
box3.addActionListener(this);
box3.setBounds(740,70,50,20);
textArea12 = new JTextArea(5, 20);
textArea12.setEditable(false);
textArea12.setBounds(740,95,50,20);
JLabel label4 = new JLabel("8");
label4.setBounds(815,50,20,20);
box4 = new JTextField(3);
box4.addActionListener(this);
box4.setBounds(795,70,50,20);
textArea13 = new JTextArea(5, 20);
textArea13.setEditable(false);
textArea13.setBounds(795,95,50,20);
JLabel label5 = new JLabel("9");
label5.setBounds(870,50,20,20);
box5 = new JTextField(3);
box5.addActionListener(this);
box5.setBounds(850,70,50,20);
textArea14 = new JTextArea(5, 20);
textArea14.setEditable(false);
textArea14.setBounds(850,95,50,20);
JLabel label6 = new JLabel("10");
label6.setBounds(922,50,20,20);
box6 = new JTextField(3);
box6.addActionListener(this);
box6.setBounds(905,70,50,20);
textArea15 = new JTextArea(5, 20);
textArea15.setEditable(false);
textArea15.setBounds(905,95,50,20);
JLabel come = new JLabel("COME");
come.setBounds(774,120,60,20);
box7 = new JTextField(3);
box7.addActionListener(this);
box7.setBounds(767,140,50,20);
textArea16 = new JTextArea(5, 20);
textArea16.setEditable(false);
textArea16.setBounds(712,140,50,20);
JLabel field = new JLabel("FIELD");
field.setBounds(774,190,60,20);
box8 = new JTextField(3);
box8.addActionListener(this);
box8.setBounds(767,210,50,20);
textArea17 = new JTextArea(5, 20);
textArea17.setEditable(false);
textArea17.setBounds(712,210,50,20);
JLabel dontPass = new JLabel("DON'T PASS");
dontPass.setBounds(760,260,90,20);
box9 = new JTextField(3);
box9.addActionListener(this);
box9.setBounds(767,280,50,20);
textArea18 = new JTextArea(5, 20);
textArea18.setEditable(false);
textArea18.setBounds(712,280,50,20);
JLabel pass = new JLabel("PASS");
pass.setBounds(774,330,60,20);
box10 = new JTextField(3);
box10.addActionListener(this);
box10.setBounds(767,350,50,20);
textArea19 = new JTextArea(5, 20);
textArea19.setEditable(false);
textArea19.setBounds(712,350,50,20);
panel.add(label1);
panel.add(box1);
panel.add(textArea10);
panel.add(label2);
panel.add(box2);
panel.add(textArea11);
panel.add(label3);
panel.add(box3);
panel.add(textArea12);
panel.add(label4);
panel.add(box4);
panel.add(textArea13);
panel.add(label5);
panel.add(box5);
panel.add(textArea14);
panel.add(label6);
panel.add(box6);
panel.add(textArea15);
panel.add(come);
panel.add(box7);
panel.add(textArea16);
panel.add(field);
panel.add(box8);
panel.add(textArea17);
panel.add(dontPass);
panel.add(box9);
panel.add(textArea18);
panel.add(pass);
panel.add(box10);
panel.add(textArea19);
die = new Die (600,500,Roll.die1());
panel.add(die);
JButton roll = new JButton("roll");
class RollListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int die1 = Roll.die1();
int die2 = Roll.die2();
System.out.println(die1 + die2);
}
}
RollListener listener = new RollListener();
roll.addActionListener(listener);
roll.setBounds(450,665,110,30);
panel.add(roll);
JLabel bankAccount = new JLabel("BALANCE: ");
bankAccount.setBounds(600, 665, 60, 30);
panel.add(bankAccount);
JTextField bank2 = new JTextField(10);
bank2.setBounds(670, 665, 80, 30);
bank2.setEditable(false);
String answer = String.valueOf(account.getBalance());
bank2.setText(answer);
panel.add(bank2);
add(panel);
//frame.add(panel);
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
String text1 = box11.getText();
textArea.setText(text1);
box11.selectAll();
textArea.setCaretPosition(textArea.getDocument().getLength());
String text2 = box12.getText();
textArea1.setText(text2);
box12.selectAll();
textArea1.setCaretPosition(textArea1.getDocument().getLength());
String text3 = box13.getText();
textArea2.setText(text3);
box13.selectAll();
textArea2.setCaretPosition(textArea2.getDocument().getLength());
String text4 = box14.getText();
textArea3.setText(text4);
box14.selectAll();
textArea3.setCaretPosition(textArea3.getDocument().getLength());
String text5 = box15.getText();
textArea4.setText(text5);
box15.selectAll();
textArea4.setCaretPosition(textArea4.getDocument().getLength());
String text6 = box16.getText();
textArea5.setText(text6);
box16.selectAll();
textArea5.setCaretPosition(textArea5.getDocument().getLength());
String text7 = box17.getText();
textArea6.setText(text7);
box17.selectAll();
textArea6.setCaretPosition(textArea6.getDocument().getLength());
String text8 = box18.getText();
textArea7.setText(text8);
box18.selectAll();
textArea7.setCaretPosition(textArea7.getDocument().getLength());
String text9 = box20.getText();
textArea8.setText(text9);
box20.selectAll();
textArea8.setCaretPosition(textArea8.getDocument().getLength());
String text10 = box19.getText();
textArea9.setText(text10);
box19.selectAll();
textArea9.setCaretPosition(textArea9.getDocument().getLength());
String text11 = box1.getText();
textArea10.setText(text11);
box1.selectAll();
textArea10.setCaretPosition(textArea10.getDocument().getLength());
String text12 = box2.getText();
textArea11.setText(text12);
box2.selectAll();
textArea11.setCaretPosition(textArea11.getDocument().getLength());
String text13 = box3.getText();
textArea12.setText(text13);
box3.selectAll();
textArea12.setCaretPosition(textArea12.getDocument().getLength());
String text14 = box4.getText();
textArea13.setText(text14);
box4.selectAll();
textArea13.setCaretPosition(textArea13.getDocument().getLength());
String text15 = box5.getText();
textArea14.setText(text15);
box5.selectAll();
textArea14.setCaretPosition(textArea14.getDocument().getLength());
String text16 = box6.getText();
textArea15.setText(text16);
box6.selectAll();
textArea15.setCaretPosition(textArea15.getDocument().getLength());
String text17 = box7.getText();
textArea16.setText(text17);
box7.selectAll();
textArea16.setCaretPosition(textArea16.getDocument().getLength());
String text18 = box8.getText();
textArea17.setText(text18);
box8.selectAll();
textArea17.setCaretPosition(textArea17.getDocument().getLength());
String text19 = box9.getText();
textArea18.setText(text19);
box9.selectAll();
textArea18.setCaretPosition(textArea18.getDocument().getLength());
String text20 = box10.getText();
textArea19.setText(text20);
box10.selectAll();
textArea19.setCaretPosition(textArea19.getDocument().getLength());
}
}
This shouldn't even compile. A Menu is not a typeof JFrame, it is a component that you may add to a frame (although with Swing you should be using the JMenu not the Menu).
It all compiles. When we compile and run CrapsGame we get a menu bar and the roll button, and when we compile and run TestTable the table that we created shows up, but it won't implement into CrapsGame.
Is Menu a custom class? I'd rename that so it doesn't conflict with awt's Menu if it is.
TestTable doesn't test if this is added, it tests on panel. The easiest fix to do here without fiddling with the rendering is to simply change the line JPanel panel = new JPanel(); to JPanel panel = this; and remove the add(panel);. I always use a layout manager, so if I had to pin the problem on something, its the lack of the layout manager being unable to determine the size of the panel.
I actually got the table working, I moved everything into TestTable, and it is working really well now. But, I can't get the menu to show up. Any ideas here?
Code:
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class TestTable extends JPanel implements ActionListener
{
private static BankAccount account = new BankAccount(1000.00);
private static final long serialVersionUID = 1L;
private static Die die;
protected JTextField box11;
protected JTextField box1;
protected JTextField box2;
protected JTextField box3;
protected JTextField box4;
protected JTextField box5;
protected JTextField box6;
protected JTextField box7;
protected JTextField box8;
protected JTextField box9;
protected JTextField box10;
protected JTextField box12;
protected JTextField box13;
protected JTextField box14;
protected JTextField box15;
protected JTextField box16;
protected JTextField box17;
protected JTextField box18;
protected JTextField box19;
protected JTextField box20;
protected JTextArea textArea;
protected JTextArea textArea1;
protected JTextArea textArea2;
protected JTextArea textArea3;
protected JTextArea textArea4;
protected JTextArea textArea5;
protected JTextArea textArea6;
protected JTextArea textArea7;
protected JTextArea textArea8;
protected JTextArea textArea9;
protected JTextArea textArea10;
protected JTextArea textArea11;
protected JTextArea textArea12;
protected JTextArea textArea13;
protected JTextArea textArea14;
protected JTextArea textArea15;
protected JTextArea textArea16;
protected JTextArea textArea17;
protected JTextArea textArea18;
protected JTextArea textArea19;
public TestTable()
{
BankAccount account = new BankAccount(1000.00);
System.out.println(account);
//Creates JFrame
JFrame frame = new JFrame();
//Creates a Jframe
JPanel panel = new JPanel();
//Adds a panel to the frame
//JPanel layout = new JPanel();
//Sets the layout of the panel
//layout.setLayout(new BorderLayout());
//Creates the table for game
JTable table = new JTable();
JScrollPane scrollPane = new JScrollPane(table);
frame.add(table);
//Adds the table to the frame in center
//layout.add(table, BorderLayout.CENTER);
frame.add(createFooter(), BorderLayout.SOUTH);
//Adds layout panel the JFrame
//frame.add(layout);
frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
//When program closed it terminates program execution
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Makes frame visible
frame.setVisible(true);
//JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JLabel hard4 = new JLabel("HARD 4");
hard4.setBounds(285,50,70,20);
box11 = new JTextField(3);
box11.addActionListener(this);
box11.setBounds(280,70,50,20);
textArea = new JTextArea(5, 20);
textArea.setEditable(false);
textArea.setBounds(225,70,50,20);
frame.add(hard4);
frame.add(box11);
frame.add(textArea);
JLabel hard6 = new JLabel("HARD 6");
hard6.setBounds(340,50,70,20);
box12 = new JTextField(3);
box12.addActionListener(this);
box12.setBounds(335,70,50,20);
textArea1 = new JTextArea(5, 20);
textArea1.setEditable(false);
textArea1.setBounds(390,70,50,20);
frame.add(hard6);
frame.add(box12);
frame.add(textArea1);
JLabel hard8 = new JLabel("HARD 8");
hard8.setBounds(285,110,70,20);
box13 = new JTextField(3);
box13.addActionListener(this);
box13.setBounds(280,130,50,20);
textArea2 = new JTextArea(5, 20);
textArea2.setEditable(false);
textArea2.setBounds(225,130,50,20);
frame.add(hard8);
frame.add(box13);
frame.add(textArea2);
JLabel hard10 = new JLabel("HARD 10");
hard10.setBounds(336,110,70,20);
box14 = new JTextField(3);
box14.addActionListener(this);
box14.setBounds(335,130,50,20);
textArea3 = new JTextArea(5, 20);
textArea3.setEditable(false);
textArea3.setBounds(390,130,50,20);
frame.add(hard10);
frame.add(box14);
frame.add(textArea3);
JLabel world = new JLabel("WORLD");
world.setBounds(310,170,70,20);
box15 = new JTextField(3);
box15.addActionListener(this);
box15.setBounds(307,190,50,20);
textArea4 = new JTextArea(5, 20);
textArea4.setEditable(false);
textArea4.setBounds(252,190,50,20);
frame.add(world);
frame.add(box15);
frame.add(textArea4);
JLabel three = new JLabel("THREE");
three.setBounds(285,230,70,20);
box16 = new JTextField(3);
box16.addActionListener(this);
box16.setBounds(280,250,50,20);
textArea5 = new JTextArea(5, 20);
textArea5.setEditable(false);
textArea5.setBounds(225,250,50,20);
frame.add(three);
frame.add(box16);
frame.add(textArea5);
JLabel twelve = new JLabel("TWELVE");
twelve.setBounds(335,230,70,20);
box17 = new JTextField(3);
box17.addActionListener(this);
box17.setBounds(335,250,50,20);
textArea6 = new JTextArea(5, 20);
textArea6.setEditable(false);
textArea6.setBounds(390,250,50,20);
frame.add(twelve);
frame.add(box17);
frame.add(textArea6);
JLabel two = new JLabel("TWO");
two.setBounds(290,290,70,20);
box18 = new JTextField(3);
box18.addActionListener(this);
box18.setBounds(280,310,50,20);
textArea7 = new JTextArea(5, 20);
textArea7.setEditable(false);
textArea7.setBounds(225,310,50,20);
frame.add(two);
frame.add(box18);
frame.add(textArea7);
JLabel craps = new JLabel("ALL CRAPS");
craps.setBounds(300,350,100,20);
box20 = new JTextField(3);
box20.addActionListener(this);
box20.setBounds(305,370,50,20);
textArea8 = new JTextArea(5, 20);
textArea8.setEditable(false);
textArea8.setBounds(250,370,50,20);
frame.add(craps);
frame.add(box20);
frame.add(textArea8);
JLabel eleven = new JLabel("ELEVEN");
eleven.setBounds(338,290,70,20);
box19 = new JTextField(3);
box19.addActionListener(this);
box19.setBounds(335,310,50,20);
textArea9 = new JTextArea(5, 20);
textArea9.setEditable(false);
textArea9.setBounds(390,310,50,20);
frame.add(eleven);
frame.add(box19);
frame.add(textArea9);
JLabel label1 = new JLabel("4");
label1.setBounds(650,50,20,20);
box1 = new JTextField(3);
box1.addActionListener(this);
box1.setBounds(630,70,50,20);
textArea10 = new JTextArea(5, 20);
textArea10.setEditable(false);
textArea10.setBounds(630,95,50,20);
JLabel label2 = new JLabel("5");
label2.setBounds(705,50,20,20);
box2 = new JTextField(3);
box2.addActionListener(this);
box2.setBounds(685,70,50,20);
textArea11 = new JTextArea(5, 20);
textArea11.setEditable(false);
textArea11.setBounds(685,95,50,20);
JLabel label3 = new JLabel("6");
label3.setBounds(760,50,20,20);
box3 = new JTextField(3);
box3.addActionListener(this);
box3.setBounds(740,70,50,20);
textArea12 = new JTextArea(5, 20);
textArea12.setEditable(false);
textArea12.setBounds(740,95,50,20);
JLabel label4 = new JLabel("8");
label4.setBounds(815,50,20,20);
box4 = new JTextField(3);
box4.addActionListener(this);
box4.setBounds(795,70,50,20);
textArea13 = new JTextArea(5, 20);
textArea13.setEditable(false);
textArea13.setBounds(795,95,50,20);
JLabel label5 = new JLabel("9");
label5.setBounds(870,50,20,20);
box5 = new JTextField(3);
box5.addActionListener(this);
box5.setBounds(850,70,50,20);
textArea14 = new JTextArea(5, 20);
textArea14.setEditable(false);
textArea14.setBounds(850,95,50,20);
JLabel label6 = new JLabel("10");
label6.setBounds(922,50,20,20);
box6 = new JTextField(3);
box6.addActionListener(this);
box6.setBounds(905,70,50,20);
textArea15 = new JTextArea(5, 20);
textArea15.setEditable(false);
textArea15.setBounds(905,95,50,20);
JLabel come = new JLabel("COME");
come.setBounds(774,120,60,20);
box7 = new JTextField(3);
box7.addActionListener(this);
box7.setBounds(767,140,50,20);
textArea16 = new JTextArea(5, 20);
textArea16.setEditable(false);
textArea16.setBounds(712,140,50,20);
JLabel field = new JLabel("FIELD");
field.setBounds(774,190,60,20);
box8 = new JTextField(3);
box8.addActionListener(this);
box8.setBounds(767,210,50,20);
textArea17 = new JTextArea(5, 20);
textArea17.setEditable(false);
textArea17.setBounds(712,210,50,20);
JLabel dontPass = new JLabel("DON'T PASS");
dontPass.setBounds(760,260,90,20);
box9 = new JTextField(3);
box9.addActionListener(this);
box9.setBounds(767,280,50,20);
textArea18 = new JTextArea(5, 20);
textArea18.setEditable(false);
textArea18.setBounds(712,280,50,20);
JLabel pass = new JLabel("PASS");
pass.setBounds(774,330,60,20);
box10 = new JTextField(3);
box10.addActionListener(this);
box10.setBounds(767,350,50,20);
textArea19 = new JTextArea(5, 20);
textArea19.setEditable(false);
textArea19.setBounds(712,350,50,20);
frame.add(label1);
frame.add(box1);
frame.add(textArea10);
frame.add(label2);
frame.add(box2);
frame.add(textArea11);
frame.add(label3);
frame.add(box3);
frame.add(textArea12);
frame.add(label4);
frame.add(box4);
frame.add(textArea13);
frame.add(label5);
frame.add(box5);
frame.add(textArea14);
frame.add(label6);
frame.add(box6);
frame.add(textArea15);
frame.add(come);
frame.add(box7);
frame.add(textArea16);
frame.add(field);
frame.add(box8);
frame.add(textArea17);
frame.add(dontPass);
frame.add(box9);
frame.add(textArea18);
frame.add(pass);
frame.add(box10);
frame.add(textArea19);
die = new Die (0,0,Roll.die1());
frame.add(die);
JButton roll = new JButton("roll");
class RollListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int die1 = Roll.die1();
int die2 = Roll.die2();
System.out.println(die1 + die2);
}
}
RollListener listener = new RollListener();
roll.addActionListener(listener);
roll.setBounds(450,665,110,30);
panel.add(roll);
JLabel bankAccount = new JLabel("BALANCE: ");
bankAccount.setBounds(600, 665, 60, 30);
panel.add(bankAccount);
JTextField bank2 = new JTextField(10);
bank2.setBounds(670, 665, 80, 30);
bank2.setEditable(false);
String answer = String.valueOf(account.getBalance());
bank2.setText(answer);
panel.add(bank2);
add(panel);
//frame.add(panel);
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//frame.setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
int die1 = Roll.die1();
int die2 = Roll.die2();
TestBet test = new TestBet(die1,die2);
String text1 = box11.getText();
textArea.setText(text1);
box11.selectAll();
textArea.setCaretPosition(textArea.getDocument().getLength());
String text2 = box12.getText();
textArea1.setText(text2);
box12.selectAll();
textArea1.setCaretPosition(textArea1.getDocument().getLength());
String text3 = box13.getText();
textArea2.setText(text3);
box13.selectAll();
textArea2.setCaretPosition(textArea2.getDocument().getLength());
String text4 = box14.getText();
textArea3.setText(text4);
box14.selectAll();
textArea3.setCaretPosition(textArea3.getDocument().getLength());
String text5 = box15.getText();
textArea4.setText(text5);
box15.selectAll();
textArea4.setCaretPosition(textArea4.getDocument().getLength());
String text6 = box16.getText();
textArea5.setText(text6);
box16.selectAll();
textArea5.setCaretPosition(textArea5.getDocument().getLength());
String text7 = box17.getText();
textArea6.setText(text7);
box17.selectAll();
textArea6.setCaretPosition(textArea6.getDocument().getLength());
String text8 = box18.getText();
textArea7.setText(text8);
box18.selectAll();
textArea7.setCaretPosition(textArea7.getDocument().getLength());
String text9 = box20.getText();
textArea8.setText(text9);
box20.selectAll();
textArea8.setCaretPosition(textArea8.getDocument().getLength());
String text10 = box19.getText();
textArea9.setText(text10);
box19.selectAll();
textArea9.setCaretPosition(textArea9.getDocument().getLength());
String text11 = box1.getText();
textArea10.setText(text11);
box1.selectAll();
textArea10.setCaretPosition(textArea10.getDocument().getLength());
String text12 = box2.getText();
textArea11.setText(text12);
box2.selectAll();
textArea11.setCaretPosition(textArea11.getDocument().getLength());
String text13 = box3.getText();
textArea12.setText(text13);
box3.selectAll();
textArea12.setCaretPosition(textArea12.getDocument().getLength());
String text14 = box4.getText();
textArea13.setText(text14);
box4.selectAll();
textArea13.setCaretPosition(textArea13.getDocument().getLength());
String text15 = box5.getText();
textArea14.setText(text15);
box5.selectAll();
textArea14.setCaretPosition(textArea14.getDocument().getLength());
String text16 = box6.getText();
textArea15.setText(text16);
box6.selectAll();
textArea15.setCaretPosition(textArea15.getDocument().getLength());
String text17 = box7.getText();
textArea16.setText(text17);
box7.selectAll();
textArea16.setCaretPosition(textArea16.getDocument().getLength());
String text18 = box8.getText();
textArea17.setText(text18);
box8.selectAll();
textArea17.setCaretPosition(textArea17.getDocument().getLength());
String text19 = box9.getText();
textArea18.setText(text19);
box9.selectAll();
textArea18.setCaretPosition(textArea18.getDocument().getLength());
String text20 = box10.getText();
textArea19.setText(text20);
box10.selectAll();
textArea19.setCaretPosition(textArea19.getDocument().getLength());
}
public static Component createFooter()
{
//Creates a new JPanel
JPanel panel = new JPanel();
//Creates a JButton called roll
JButton roll = new JButton("roll");
//This listener creates two random die and saves their values
class RollListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
int die1 = Roll.die1();
int die2 = Roll.die2();
System.out.println(die1 + die2);
}
}
//Creates the listener to add to button
RollListener listener = new RollListener();
//Adds listener to button
roll.addActionListener(listener);
//Sets where to place the button
roll.setBounds(450,665,110,30);
//Adds the button to panel
panel.add(roll);
//Creates a new JLabel
JLabel bankAccount = new JLabel("BALANCE: ");
//Sets the location of the label
bankAccount.setBounds(600, 665, 60, 30);
//Adds the label to the panel
panel.add(bankAccount);
//Creates a JTextField
JTextField bank2 = new JTextField(10);
//Sets location to put the JTextField
bank2.setBounds(670, 665, 80, 30);
//Sets the JTextField to uneditable
bank2.setEditable(false);
//sets BankAccount balance into a string
String answer = String.valueOf(account.getBalance());
//sets the string into the JTextField
bank2.setText(answer);
//Adds to the panel
panel.add(bank2);
//Returns panel
return panel;
}
}