Chyba nie umiem. Poniżej całość moich "wypocin":
public class Rozliczenie extends JFrame
{
private JButton b1;
private JButton b2;
private JTextField t;
public JTextField t1;
public JComboBox pracownik;
public JComboBox status;
private TextArea pole1;
public Rozliczenie()
{
setTitle("ROZLICZNIK");
setLayout(null);
setLocation(280, 200);
setVisible(true);
setSize(750,450);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.gray);
JLabel label1 = new JLabel();
label1.setBounds(650,10,80,80);
add(label1);
label1.setIcon(new ImageIcon("logo.gif"));
JLabel tytul= new JLabel("Rozliczenie");
tytul.setBounds(310,20,400,30);
tytul.setForeground (Color.white);
add(tytul);
add(t=new JTextField(8));
JLabel label2 = new JLabel("Pracownik");
label2.setBounds(120,130,80,30);
label2.setForeground (Color.white);
add(label2);
b1=new JButton("Zatwierdź");
b1.setBounds(280,305,150,30);
b1.setBackground (Color.green);
add(b1);
b2=new JButton("Powrót");
b2.setBounds( 280,355,150,30);
b2.setBackground (Color.green);
add(b2);
final JTextField t1=new JTextField("Data");
t1.setBounds(360,170,150,30);
t1.setBackground (Color.lightGray);
DateFormat d= new SimpleDateFormat("dd.MMMMM ");
Date today = Calendar.getInstance().getTime();
String wyswietlDate = d.format(today);
t1.setText(" " + wyswietlDate);
t1.setEditable(false);
add(t1);
String kalendarz=t1.getText();
JLabel label3 = new JLabel("Data");
label3.setBounds(415,130,80,30);
label3.setForeground (Color.white);
add(label3);
JLabel label4 = new JLabel("Status");
label4.setBounds(585,130,80,30);
label4.setForeground (Color.white);
add(label4);
pracownik = new JComboBox();
Connection c = null;
Statement stmt = null;
try
{
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jacek","jacek", "zuza");
c.setAutoCommit(false);
System.out.println("Dostęp do bazy danych \n");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "select id_pracownika,nazwisko,imie from pracownicy;" );
pracownik.addItem(" \n");
while ( rs.next() )
{
pracownik.addItem(rs.getInt("id_pracownika" )+ " " + rs.getString( "imie") + " " + rs.getString("nazwisko"));
}
rs.close();
stmt.close();
c.close();
}
catch ( Exception e )
{
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
pracownik.setBounds(60,170,250,30);
pracownik.setBackground(Color.lightGray);
add(pracownik);
String statusy []={" ","obecny","nieobecny","urlop","chory","dzien_wolny"};
status = new JComboBox(statusy);
status.setBounds(565,170,120,30);
status.setBackground(Color.lightGray);
status.setSelectedIndex(0);
status.addActionListener(myStatListener);
add(status);
/////////////-------------Tutaj to wstawiłem.
private class MyStatListener implements ActionListener
{
public String stat;
public void actionPerformed(ActionEvent actionevent)
{
JComboBox status = (JComboBox) actionevent.getSource();
stat = (String)status.getSelectedItem();
}
}
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
dispose();
Program okno=new Program();
okno.setVisible(true);
}
});
}
public static void main(String args[])
{
new Rozliczenie();
}
}
Proszę o sugestie.