• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Question

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic