我是新来的,希望我能正确提交,因为我知道内容应该一致。无论如何我正在为ATM模拟器制作一个GUI程序,并且遇到添加麻烦(mainPanel());错误是找不到符号 symbol:方法mainPanel()
代码如下:
package atmproject;
/**
*
*
* 9/10/2015
*/
import javax.swing.*;
import java.awt.*;
public class ATMProject extends JFrame {
//create frame/Constructor
static final int WIDTH = 300, HEIGHT = 200;
public ATMProject(){
super("ATMProject");
setFrame(WIDTH,HEIGHT);
}
public ATMProject(String title){
super(title);
setFrame(WIDTH,HEIGHT);
}
public ATMProject(String title, int width, int height){
super(title);
setFrame(width,height);
}
public void display(){
setVisible(true);
}
private void setFrame (int width, int height){
setSize(width, height);
setLocation(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public JFrame atmFrame;
public void myFrame(){
atmFrame = new JFrame();
atmFrame.setVisible(true);
atmFrame.setSize(300,200);
atmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//create buttons
private JButton withdrawal = new JButton("Withdrawal");
private JButton deposit = new JButton("Deposit");
private JButton transferTo = new JButton("Transfer To");
private JButton balance = new JButton("Balance");
//set text field
private JTextField output = new JTextField("");
//set radio buttons
//panel construction class
public void ATMPanel (){
setLayout (new BorderLayout());
setBackground (Color.lightGray);
//main panel
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout (3,2,5,5));
//result text color????
output.setEditable(false);
//add buttons to panel
mainPanel.add(withdrawal);
mainPanel.add(deposit);
mainPanel.add(transferTo);
mainPanel.add(balance);
//radio buttons!!!!!!!!!
//mainPanel.add(balance);
//mainPanel.add(balance);
//output
mainPanel.add(output);
add(mainPanel, BorderLayout.CENTER);
mainPanel.setVisible(true);
atmFrame.add(mainPanel);
}
public class AtmApplication extends ATMProject{
public AtmApplication() {
super("ATM Machine", 300, 200);
add(mainPanel());
}
}
public static void main(String[] args) {
ATMProject test = new ATMProject();
add(new mainPanel());
}
}