我不能将这个TextField添加到界面中,生成的窗口很简单,没有任何细节,尽管我已经尝试了很多来找到问题所在..这里是代码: import java.awt.ComponentOrientation; import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.UIManager;
public class Calculator extends JFrame {
private JTextField display;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Could not load system interface\n");
}
new Calculator();
}
public Calculator() {
super("Calculator");
sendDisplay();
sendUI(this);
}
private void sendDisplay() {
display = new JTextField("0");
display.setBounds(10, 10, 324, 50);
display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
display.setEditable(false);
display.setFont(new Font("Arial", Font.PLAIN, 30));
display.setVisible(true);
add(display);
}
private void sendUI(Calculator app) {
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setVisible(true);
app.setSize(400, 600);
app.setLayout(null);
app.setResizable(false);
app.setLocationRelativeTo(null);
}
}
如果有人能找到问题,我将不胜感激
答案 0 :(得分:2)
让setVisible(true)
成为sendUI
方法
private void sendUI(Calculator app) {
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(400,600);
app.setLayout(null);
app.setResizable(false);
app.setLocationRelativeTo(null);
app.setVisible(true);
}
良好做法