我的代码工作比我添加了更多的代码而不是删除它,现在我的代码不再运行了。每次我点击运行它会显示一个绿色的加载栏,然后没有任何反应。我想知道这是否与我错过的代码有关。
class AmortizationLayout implements ActionListener {
AmortizationLayout() {
JPanel jp = new JPanel(new BorderLayout(2,2));
jp.setPreferredSize( new Dimension( 640, 480 ) );
JPanel labelFields = new JPanel(new BorderLayout(2,2));
labelFields.setBorder(new TitledBorder("Welcome"));
JPanel jl = new JPanel(new GridLayout(0,1,1,1));
JPanel jf = new JPanel(new GridLayout(0,1,1,1));
jp.setVisible(true);
String[] dropdown = {"Buy", "Sell"};
JComboBox options = new JComboBox(dropdown);
JLabel BORS = new JLabel("Buy Or Sell");
options.setSelectedIndex(0);
options.addActionListener(this);
String[] dropdown2 = {"APPLE", "MICROSOFT", "GOOGLE"};
JComboBox options2 = new JComboBox(dropdown2);
JLabel S2P = new JLabel("Stock To Purchase");
options.setSelectedIndex(0);
options.addActionListener(this);
jl.add(new JLabel("Price($)" ));
jf.add(new JTextField(30));
jl.add(options2);
jf.add(S2P);
jl.add(new JLabel("FX Rate " ));
jf.add(new JTextField(30));
jl.add(new JLabel("Money to Spend" ));
jf.add(new JTextField(30));
jl.add(options);
jf.add(BORS);
labelFields.add(jl, BorderLayout.CENTER);
labelFields.add(jf, BorderLayout.EAST);
JPanel PCenter = new JPanel(new BorderLayout(2,2));
PCenter.setBorder(new TitledBorder("Confirmation"));
JPanel SubT = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton btNewTask = new JButton("produce ticket");
SubT.add(btNewTask );
PCenter.add( SubT , BorderLayout.NORTH );
PCenter.add(new JScrollPane(new JTextArea(5,30)));
jp.add(labelFields, BorderLayout.NORTH);
jp.add(PCenter, BorderLayout.CENTER);
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new AmortizationLayout();
}
});
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}
答案 0 :(得分:0)
缺少框架。
添加
JFrame frame = new JFrame("Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(jp);
frame.pack();
frame.setVisible(true);
到AmortizationLayout
。