| | |
i need help
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 7
Reputation:
Solved Threads: 0
following masijade advice i tried busting my head abit. i have written the following code
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Game extends JApplet implements ActionListener
{
//Creating a new JPanel called panel1
JPanel panel1 = new JPanel();
//Creating a JLabel for panel1
JLabel header = new JLabel("Simple Random Numbers Game 4 Two Players");
//Seting the font for panel1
Font bigFont = new Font("Tahoma", Font.ITALIC, 18);
//Creating a new JPanel called panel2
JPanel panel2 = new JPanel();
//Creating a JLabel R1 which receives a parameter "player1"
JLabel R1 = new JLabel("Player 1");
//Creating a JTextField Player1
JTextField player1 = new JTextField("",6);
JLabel R2 = new JLabel("Player 2");
JTextField player2 = new JTextField("",6);
JLabel amount = new JLabel("Winning Amount");
JTextField amnt = new JTextField("",6);
//panel3 and its contents
JPanel panel3 = new JPanel();
JButton random = new JButton("Random");
JButton clear = new JButton("Clear");
//seting the layout to be used in the game applet
FlowLayout flow = new FlowLayout();
//initiallising the Applet
public void init()
{
header.setFont(bigFont);
Container con = getContentPane();
//defining the layouts for each of the three panels
panel1.setLayout(new GridLayout(4,1,10,10));
panel2.setLayout(new GridLayout(1,1,6,6));
panel3.setLayout(new GridLayout(1,1,5,5));
//adding the panels and components to the container
con.add(panel1);
panel1.setBorder(new TitledBorder ("Controls"));
panel1.add(header);
panel1.add(panel2);
panel1.add(panel3);
panel2.setBorder(new TitledBorder (""));
panel2.add(R1);
panel2.add(player1);
panel2.add(R2);
panel2.add(player2);
panel2.add(amount);
panel2.add(amnt);
panel3.setBorder(new TitledBorder (""));
panel3.add(random);
panel3.add(clear);
con.setLayout(new FlowLayout());//setting the defined layout
//registering text tips to the buttons
random.setToolTipText("Press to play");
clear.setToolTipText("Press to reset");
//registering mnemonics to the buttons
random.setMnemonic('R');
clear.setMnemonic('C');
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if(source == random)
{
String name = amnt.getText();
System.out.println("it ends here"+amount);
}
}
}
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class Game extends JApplet implements ActionListener
{
//Creating a new JPanel called panel1
JPanel panel1 = new JPanel();
//Creating a JLabel for panel1
JLabel header = new JLabel("Simple Random Numbers Game 4 Two Players");
//Seting the font for panel1
Font bigFont = new Font("Tahoma", Font.ITALIC, 18);
//Creating a new JPanel called panel2
JPanel panel2 = new JPanel();
//Creating a JLabel R1 which receives a parameter "player1"
JLabel R1 = new JLabel("Player 1");
//Creating a JTextField Player1
JTextField player1 = new JTextField("",6);
JLabel R2 = new JLabel("Player 2");
JTextField player2 = new JTextField("",6);
JLabel amount = new JLabel("Winning Amount");
JTextField amnt = new JTextField("",6);
//panel3 and its contents
JPanel panel3 = new JPanel();
JButton random = new JButton("Random");
JButton clear = new JButton("Clear");
//seting the layout to be used in the game applet
FlowLayout flow = new FlowLayout();
//initiallising the Applet
public void init()
{
header.setFont(bigFont);
Container con = getContentPane();
//defining the layouts for each of the three panels
panel1.setLayout(new GridLayout(4,1,10,10));
panel2.setLayout(new GridLayout(1,1,6,6));
panel3.setLayout(new GridLayout(1,1,5,5));
//adding the panels and components to the container
con.add(panel1);
panel1.setBorder(new TitledBorder ("Controls"));
panel1.add(header);
panel1.add(panel2);
panel1.add(panel3);
panel2.setBorder(new TitledBorder (""));
panel2.add(R1);
panel2.add(player1);
panel2.add(R2);
panel2.add(player2);
panel2.add(amount);
panel2.add(amnt);
panel3.setBorder(new TitledBorder (""));
panel3.add(random);
panel3.add(clear);
con.setLayout(new FlowLayout());//setting the defined layout
//registering text tips to the buttons
random.setToolTipText("Press to play");
clear.setToolTipText("Press to reset");
//registering mnemonics to the buttons
random.setMnemonic('R');
clear.setMnemonic('C');
}
public void actionPerformed(ActionEvent thisEvent)
{
Object source = thisEvent.getSource();
if(source == random)
{
String name = amnt.getText();
System.out.println("it ends here"+amount);
}
}
}
This is a continuation of http://www.daniweb.com/forums/thread120574.html
Please stick with that thread. I have asked the admins to delete the third thread you created and asked them to close this one.
Please stick with that thread. I have asked the admins to delete the third thread you created and asked them to close this one.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Other Threads in the Java Forum
- Previous Thread: Comparing Stringtokenizer Tokens
- Next Thread: Sound recorder DLL
Views: 418 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
6 android api apple applet application arguments array arrays automation binary bluetooth bold byte c++ chat class classes client code component coordinates database datagram doctype draw eclipse educational error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework html ide ideas image ingres input integer internet intersect ip j2me java javaexcel javaprojects jmf jni jpanel jtextarea julia linux list loop map method methods mobile netbeans newbie nextline number object oracle pong print problem program programming project recursion recursive scanner screen sell server set size sms socket sort sql string swing test threads time transfer tree user web websites windows





