我正在尝试使用几个文本框创建小型GUI。最短的代码在这里:
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MortgageCalculator implements ActionListener {
JTextField loanAmount, loanTerm;
JFrame jf;
public static void main(String[] args) {
// TODO Auto-generated method stub
mygui mg = new mygui();
mg.initUIPanel();
}
public void initUIPanel() {
jf = new JFrame();
jf.setTitle("my gui");
jf.setLocation(300, 400);
jf.setSize(400, 500);
jf.setVisible(true);
jf.setResizable(false);
jf.show();
JPanel panel = new JPanel();
panel.setLayout(null);
loanAmount = new JTextField(15);
loanAmount.setBounds(170, 20, 125, 20);
loanTerm = new JTextField(15);
loanTerm.setBounds(170, 60, 125, 20);
panel.add(loanAmount);
panel.add(loanTerm);
jf.add(panel, "Center");
}
}
问题是它只显示框架而不显示txtbox。只有在最大化一次框架后才能看到这些框。如果再次最小化它,那么我仍然可以看到它们,但一开始不是。我做错了什么?
答案 0 :(得分:0)