简体   繁体   中英

When I click Run nothing happens

My code worked than I added some more code to it than deleted it and now my code won't run any more. Every time I click on run it shows a green loading bar then nothing happens after that. I was wondering if it was something to do with my code that I missed out.

    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

}

}

The frame is missing.

Add

JFrame frame = new JFrame("Frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(jp);
frame.pack();
frame.setVisible(true);

to AmortizationLayout .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM