J
Javanuub
Gast
Hallo zusammen,
ich habe verschiedene Buttons erstellt und möchte jetzt beim drücken der Button eine Textausgabe nicht in der Konsole ausgeben sondern in einem JTextField haben. Ich weiß nur nicht wie ich das verknüpfe!
Hier mein Code:
ich habe verschiedene Buttons erstellt und möchte jetzt beim drücken der Button eine Textausgabe nicht in der Konsole ausgeben sondern in einem JTextField haben. Ich weiß nur nicht wie ich das verknüpfe!
Hier mein Code:
Java:
import java.awt.Button;
import java.awt.Color;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Form1
{
public static void main(String [] args)
{
JFrame a = new JFrame();
a.setSize(900, 600);
a.setVisible(true);
a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
a.setLayout(null);
JTextField textField1=new JTextField();
textField1.setBackground( Color.BLACK );
textField1.setForeground( Color.YELLOW );
textField1.setEditable(false);
textField1.setSize(500,100);
textField1.setLocation(new Point(300 , 10));
a.add(textField1);
Button b = new Button("Anna Ampel");
b.setSize(180, 30);
b.setLocation(new Point(10 , 10));
b.setVisible(true);
a.add(b);
Button c = new Button("Sergej Fährlich");
c.setSize(180, 30);
c.setLocation(new Point(10 , 50));
c.setVisible(true);
a.add(c);
Button d = new Button("Max Mustermann");
d.setSize(180, 30);
d.setLocation(new Point(10 , 90));
d.setVisible(true);
a.add(d);
Button e = new Button("Miri Musterfrau");
e.setSize(180, 30);
e.setLocation(new Point(10 , 130));
e.setVisible(true);
a.add(e);
//--------------------------------------------------------------------------
ActionListener a1 = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
System.out.println("Button b Text.");
}
};
b.addActionListener( a1 );
;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
ActionListener a2 = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
System.out.println("Button c Text.");
}
};
c.addActionListener( a2 );
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
ActionListener a3 = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
System.out.println("Button d Text.");
}
};
d.addActionListener( a3 );
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
ActionListener a4 = new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
System.out.println("Button e Text.");
}
};
e.addActionListener( a4 );
//--------------------------------------------------------------------------
}
}