It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Java Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Java Question" Watch "Java Question" New topic
Author

Java Question

Theotis Jones
Greenhorn

Joined: Oct 02, 2004
Posts: 2
New to the game, brand spanken new. Is there a Java expert out
there that could tell why my buttons won't work for this java
school project.

javax.swing.*;
import java.awt.*;

public class MyCal extends JFrame{
public MyCal() {
// set up the frame
super("Calculator");
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
Container pane = getContentPane();
FlowLayout www = new FlowLayout();
pane.setLayout(www);
/*== OPERATION BUTTONS ==*/
JButton 0 = new JButton('0');
JButton 1 = new JButton('1');
JButton 2 = new JButton('2');
JButton 3 = new JButton('3');
JButton 4 = new JButton('4');
JButton 5 = new JButton('5');
JButton 6 = new JButton('6');
JButton 4 = new JButton('7');
JButton 5 = new JButton('8');
JButton 6 = new JButton('9');
pane.add(0);
pane.add(1);
pane.add(2);
pane.add(3);
pane.add(4);
pane.add(5);
pane.add(6);
pane.add(7);
pane.add(8);
pane.add(9);
}

public static void main(String[] arguments){
MyCal cal = new MyCal();
}

}

Thanks
Theotis
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Welcome to Javaranch. Since this question is about Swing GUI stuff, I am going to move it to our Swing forum.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

By "not work" what exactly do you mean? What do you expect the application to do?
Theotis Jones
Greenhorn

Joined: Oct 02, 2004
Posts: 2
This project involvs designing GUI interface for
a calculator. And I get error messages starting with
JButton 0.

Theotis
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Theotis Jones:
This project involvs designing GUI interface for
a calculator. And I get error messages starting with
JButton 0.

Theotis


What error messages would those be? Of course, I bet I could guess in that variables in Java cannot start with a number. You could have b0 or button0, but not just 0.

Future tip - When receiving error messages, you need to show us those messages so we can help.
[ October 02, 2004: Message edited by: Gregg Bolinger ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Question