allora io ho una classe in cui creo un frame principale, come segue:
codice:
B_HOME(){
JButton d_estr = new JButton("Gestione SCRIPT");
salva.setEnabled(false);
modifica.setEnabled(false);
cancella.setEnabled(false);
stampa.setEnabled(false);
selezionaTutti.setEnabled(false);
JComboBox combo = new JComboBox();
final JButton estrai =new JButton("estrai");
JPanel p1 = new JPanel(new GridBagLayout());
JPanel p2 = new JPanel(new GridBagLayout());
JPanel p3 = new JPanel(new GridBagLayout());
setTitle("ScriptManager");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension d = getToolkit().getScreenSize();
setSize(d);
//i=i.getScaledInstance(NEW_W,NEW_H,Image.SCALE_DEFAULT);
//Image i=Toolkit.getDefaultToolkit().createImage("C:/Documents and Settings/G.Costanz0/Desktop/Logo_.gif");
//icon = new ImageIcon(i);
// Icon icon = new ImageIcon(i);
l.setIcon(icon);
getContentPane().add(p);
GridBagConstraints c = new GridBagConstraints();
c.gridx=0;
c.gridy =0;
c.gridwidth =3;
c.fill = GridBagConstraints.LINE_START;
p.add(l,c);
p.addComponentListener(new ComponentListener(){
public void componentResized(ComponentEvent arg0) {
new_w=l.getWidth();
new_h=l.getHeight();
i=i.getScaledInstance(new_w,new_h,Image.SCALE_DEFAULT);
icon = new ImageIcon(i);
l.setIcon(icon);
}public void componentMoved(ComponentEvent arg0) {}
public void componentShown(ComponentEvent arg0) {}
public void componentHidden(ComponentEvent arg0) {}
});
c = new GridBagConstraints();
c.gridx=0;
c.gridy=1;//c.weighty=2.0;
c.fill =GridBagConstraints.BOTH;
p.add(p1,c);
c = new GridBagConstraints();
c.gridx=0;
c.gridy =2;c.weighty =1.0;
c.fill =GridBagConstraints.BOTH;
p.add(p2,c);
c = new GridBagConstraints();
c.gridx=0;
c.gridy =3;c.weighty =1.0;
c.fill =GridBagConstraints.BOTH;
p.add(p3,c);
c = new GridBagConstraints();
c.gridx=1;
c.gridy=1;
c.weightx=3.5;
c.fill =GridBagConstraints.BOTH;
p.add(p_job,c);
c = new GridBagConstraints();
c.gridx=1;
c.gridy =2; c.gridheight =2;c.gridwidth =2;
c.weighty=5.0;
c.fill =GridBagConstraints.BOTH;
p.add(p_job2,c);
c = new GridBagConstraints();
c.gridx=2;
c.gridy =1;
c.weighty=1.5;
c.weightx=1;
c.fill =GridBagConstraints.BOTH;
p.add(p_job3,c);
c = new GridBagConstraints();
c.gridx=0;
c.gridy =4; c.gridwidth =3;
c.fill =GridBagConstraints.HORIZONTAL;
p.add(p_job4,c);
/* c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0; //c.weighty = 0.5;
c.gridwidth=2;
c.fill = GridBagConstraints.HORIZONTAL;*/
p_job3.add(combo,BorderLayout.NORTH);
combo.setEnabled(false);
/* c = new GridBagConstraints();
c.gridx = 1;
c.gridy = 1;
c.weightx =1.0;
c.weighty =1.0; */
p_job3.add(estrai,BorderLayout.CENTER);
estrai.setEnabled(false);
c = new GridBagConstraints();
p1.add(estr,c);
p1.setBorder(BorderFactory.createTitledBorder("Inserimento script"));//intitola il pannello
JButton d_search = new JButton("Gestione PAGINA");
c = new GridBagConstraints();
c.gridy = 0;
c.weightx =1.0;
c.weighty =2.0;
c.fill=GridBagConstraints.HORIZONTAL;
p2.add(d_estr,c);
c = new GridBagConstraints();
c.gridy = 1;
c.weightx =1.0;
c.weighty =2.0;
c.fill=GridBagConstraints.HORIZONTAL;
p2.add(d_search,c);
p2.setBorder(BorderFactory.createTitledBorder("Gestione"));
JButton e_clear = new JButton("Pulizia");
JButton e_clearAll = new JButton("Gestione PULIZIA");
d_search.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
}
} );
e_clear.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
}
} );
e_clearAll.setBounds(10, 70, 150, 40);
e_clearAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
}
} );
c = new GridBagConstraints();
c.gridy = 0;
c.weightx =1.0;
c.weighty =2.0;
c.fill=GridBagConstraints.HORIZONTAL;
p3.add(e_clear,c);
c = new GridBagConstraints();
c.gridy = 1;
c.weightx =1.0;
c.weighty =2.0;
c.fill=GridBagConstraints.HORIZONTAL;
p3.add(e_clearAll,c);
p3.setBorder(BorderFactory.createTitledBorder("Pulizia"));
p_job4.add(salva);
p_job4.add(modifica);
p_job4.add(cancella);
p_job4.add(stampa);
p_job4.add(selezionaTutti);
p_job.setBorder(BorderFactory.createTitledBorder("informazioni estrazione"));
p_job2.setBorder(BorderFactory.createTitledBorder("script"));
p_job3.setBorder(BorderFactory.createTitledBorder("tasti di lavoro"));
p_job4.setBorder(BorderFactory.createTitledBorder("informazioni"));
estr.addActionListener(this);
estr.setEnabled(true);
d_estr.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
}
} );
estr.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent a)
{
FontController fc = new FontController();
//Mainframe.dispose();
fc.estrazione();
}
} );
setVisible(true);
//p_job3.setVisible(true);
}
public static void main(String[] args)
{
B_HOME b = new B_HOME();
}
dove nel costruttore main avvio il programma