How can I write the program

I would like to know how can i Change the program so that the Message'What is the sum of X and Y' can be shown in a GUI after I click the Start Button.

The program is shown below. Please help me,Thank You Very Much!

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class client2 {

public static void main(String[] args){

Frame f = new ClientFrame("Client");

f.setSize(400,400);

f.setVisible(true);

}

}

class ClientFrame extends JFrame{

JPanel StartPanel = new JPanel();

JPanel OutputPanel = new JPanel();

String Question;

JLabel label=new JLabel(Question);

Button GameStart = new Button("Start the Game");

Container c=this.getContentPane();

public ClientFrame(String title){

super (title);

c.setLayout (new BorderLayout());

StartPanel.add(GameStart);

OutputPanel.add(label);

c.add(StartPanel,BorderLayout.NORTH);

c.add(OutputPanel,BorderLayout.CENTER);

GameStart.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent Evt) {

GameStart.setEnabled(false);

Integer x=10;

Integer y=20;

Question ="What is the sum of "+x+ "and" +y;

System.out.println("Java rules!");

}

});

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent evt) {

System.exit(0);

}

});

}

}

[1483 byte] By [@@Scottiea] at [2007-11-26 20:21:45]
# 1

This code won't even compile.

Anyway, you should set the field Question's value to the String, when you declare it, before you use it in the label.

Also, you should name your local variables with names that start with lower-case letters. That's one of Java's naming conventions, and it makes your code easier to read.

paulcwa at 2007-7-10 0:46:48 > top of Java-index,Java Essentials,Java Programming...