public class JAutoDialogo extends JFrame { private JTextField t1; private JTextField t2; public static void main(String argv[]){ JAutoDialogo ist = new JAutoDialogo(); }//end main JAutoDialogo(){ JPanel pannelloTesto = new JPanel(new GridLayout(0,2,3,3)); JPanel pannelloBottoni = new JPanel(); setTitle(getClass().getName()); pannelloTesto.add(new JLabel("Testo1"),JLabel.LEFT); pannelloTesto.add(t1 = new JTextField("")); pannelloTesto.add(new JLabel("Testo2"),JLabel.LEFT); pannelloTesto.add(t2 = new JTextField("")); pannelloBottoni.setLayout(new FlowLayout()); ((JButton) pannelloBottoni.add(new JButton ("Scambia"))) .addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String scambio = t1.getText(); t1.setText(t2.getText()); t2.setText(scambio); }//end actionPerformed }); ((JButton) pannelloBottoni.add(new JButton ("Esci"))) .addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ System.exit(0); }//end actionPerformed }); getContentPane().add(pannelloTesto,"Center"); getContentPane().add(pannelloBottoni,"South"); pack(); setVisible(true); }//end costruttore AutoDiaologo }//end class JAutoDialogo
I'm working in the directory c:\lavoro, when I do:
c:\lavoro> java JAutoDialogo
I have this error :
Exception in thread "main" java.lang illegalArgumentException: illegal component position at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at jAutoDialogo.<init>(JautoDialogo.java:15) at jAutoDialogo.main(JautoDialogo.java:9)