-3
我正在通過新博士的教程和我有一個意外的錯誤。我試圖做一切Eclipse的建議,但無法弄清楚問題出在哪裏。類別無法申報類型
這是我Main Class
import javax.swing.JFrame;
class Main {
public static void main(String args[]) {
Gui go = new Gui();
go.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
go.setSize(300,200);
go.setVisible(true);
}
}
,這是GUI Class
進口java.awt.FlowLayout中; import java.awt.event.ActionListener; import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class Gui extends JFrame {
private JButton reg;
private JButton custom;
public Gui(){
super("The title");
setLayout(new FlowLayout());
reg = new JButton("Regular Button");
add(reg);
Icon b = new ImageIcon(getClass().getResource("b.png"));
Icon a = new ImageIcon(getClass().getResource("a.png"));
custom = new JButton("Custom", b);
custom.setRolloverIcon(a);
add(custom);
HandlerClass handler = new HandlerClass();
reg.addActionListener(handler);
custom.addActionListener(handler);
}
private class HandlerClass implements ActionListener{
public void actionPerformed(ActionEvent event){
JOptionPane.showMessageDialog(null, String.format("%s", event.getActionCommand()));
}
}
}
感謝兄弟們幫助我!
無法真正看到您的任何代碼。 – Sdyess 2015-02-24 10:24:49
發佈您的主類的代碼。 – mlethys 2015-02-24 10:25:13
你的GUI類的第23行是什麼?請分享您的代碼。 – 2015-02-24 10:29:04