public class Test2 extends JFrame {
String[] karte_fuer_suche = {""};
//Fenster
public Test2( int x, int y )
{
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize( x, y );
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( (d.width - getSize().width ) / 2,
(d.height - getSize().height) / 2 );
}
public static void main( String[] args )
{
final JFrame win = new Test2( 1000, 700 );
win.setTitle("Test");
win.setResizable( false );
win.getContentPane().setLayout(new FlowLayout());
win.setVisible( true );
//Button
JButton b_1 = new JButton( "Suchen" );
win.getContentPane().add(b_1);
win.setLayout( null );
b_1.setBounds( 900, 10, 85, 25 );
win.add( b_1 );
//ComboBox
String[] karte_box = {
"Test1", "Test2", "Ende};
JComboBox combo1 = new JComboBox();
for ( String s : karte_box )
combo1.addItem( s );
win.add( combo1, BorderLayout.LINE_START );
combo1.setBounds( 20, 10, 150, 20);
combo1.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e )
{
System.out.println( e );
JComboBox selectedChoice = (JComboBox) e.getSource();
if ( selectedChoice.getSelectedItem().equals( "Ende" ) ) {
System.exit( 0 );}
if ( selectedChoice.getSelectedItem().equals( "Test2" ) ){
String[] karte_fuer_suche = {"Test"};
} }
} );
//EditFeld
final JTextField suche = new JTextField( "", 30 );
win.getContentPane().add(suche);
suche.setBounds( 700, 10, 200, 25);
win.add(suche);
//test mit vergleich mit liste
b_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String[] text_suche = {suche.getText()};
if (text_suche.equals(karte_fuer_suche))
{
System.out.println("equals");
}
}
});
}
}