我試圖JOptionPane在按鈕單擊時顯示,但我不斷收到錯誤訊息,說我的建構式中缺少 return 陳述句。任何幫助將非常感激。謝謝 這是我目前的代碼。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class lab9Part1 extends JFrame implements ActionListener {
JButton button = new JButton("Show Message Dialog");
JFrame box = new JFrame();
public lab9Part1() {
super("lab9Part1");
Container c = getContentPane();
button.addActionListener(this);
c.add(button, BorderLayout.SOUTH);
setVisible(true);
setSize(500,500);
}
public static Void main (String [] args){
JFrame frame = new lab9Part1();
}
public void actionPerformed(ActionEvent e){
if (e.getSource()== button) {
JOptionPane.showMessageDialog(box,"hello","This is Cal and this is my first message dialog", JOptionPane.INFORMATION_MESSAGE);
}
}
}
uj5u.com熱心網友回復:
您在 的方法宣告中使用了Void(大寫 V) 而不是void(小寫 v) main。它應該是:
public static void main (String [] args){
JFrame frame = new lab9Part1();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/372476.html
