java Eclipse未打开框架窗口
我在EclipseIndigo中运行了这段代码,没有任何帧作为输出打开,但当我在BLUEJ中运行相同的代码时,它工作正常,并且帧正在打开。请告诉我那只虫子
这是我的密码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainFrame extends JFrame
{
void MainFrame()
{
setTitle("Square's Root Finder");
setSize(350,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLookAndFeel();
setVisible(true);
JButton but1 = new JButton("Calculate");
JLabel label1= new JLabel("Enter the number:");
JTextField t = new JTextField();
add(but1);
add(label1);
add(t);
}
private void setLookAndFeel() {
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception exc) {
// ignore error
}
}
public static void main(String[] args)
{
MainFrame newFrame = new MainFrame();
}
}
# 1 楼答案
Bug就在这一行:
将其更改为:
根据JAVA documentation,构造函数不应具有返回类型