|
-
Calculator +textfield help Howto add?
Hi, ive a question,
How can i add a textfield to show the digits that i pressed from a button?
and how do i use getsource to add get the correct digit from the buttons?
this is my code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class RekenMachine
extends Frame
implements WindowListener
{
public RekenMachine (String title)
{
super (title);
addWindowListener (this);
setLayout (new BorderLayout());
Panel p = new Panel() ;
p.setLayout (new GridLayout (4,3));
Button b1 = new Button ("1");
Button b2 = new Button ("2");
Button b3 = new Button ("3");
Button b4 = new Button ("4");
Button b5 = new Button ("5");
Button b6 = new Button ("6");
Button b7 = new Button ("7");
Button b8 = new Button ("8");
Button b9 = new Button ("9");
Button Clear = new Button ("Clear");
Button b0 = new Button ("0");
Button Stop = new Button ("Stop");
p.add(b1);
p.add(b2);
p.add(b3);
p.add(b4);
p.add(b5);
p.add(b6);
p.add(b7);
p.add(b8);
p.add(b9);
p.add(Clear);
p.add(b0);
p.add(Stop);
add (p);
}
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
public void windowActivated (WindowEvent e) { }
public void windowClosed (WindowEvent e) { }
public void windowDeactivated (WindowEvent e) { }
public void windowDeiconified (WindowEvent e) { }
public void windowIconified (WindowEvent e) { }
public void windowOpened (WindowEvent e) { }
public static void main (String [ ] argv)
{
RekenMachine ld = new RekenMachine ("RekenMachine");
ld.setSize (300, 400);
ld.setVisible (true);
}
public void actionPerformed (ActionEvent e)
{
// if (event.getSource() == b1)
// Button b1.getText();
}
public void ActionListener (ActionEvent e)
{
}
}
thnx
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks