File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Question

 
Theotis Jones
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch. Since this question is about Swing GUI stuff, I am going to move it to our Swing forum.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "not work" what exactly do you mean? What do you expect the application to do?
 
Theotis Jones
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic