• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Listener

 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant see were I went wrong when I registered the action listener can anybody help

import java.awt.*;
import java.awt.event.*;

public class formular2 extends Frame
//implements ActionListener

{
TextField Namen,Vorname,Strasse,Hausnummer, PLZ,Ort;
TextArea Ausgabe;
private final static String newline = "\n";


public static void main(String[ ] args)
{
formular2 F = new formular2();

}
public formular2()

{
super("Formularfenster");
setSize(600,400);
// den LayoutManager f�r die Klasse selbst
// 6 Zeilen und 1 Spalte 5 Pixel Abstand
// dazwischen
//Instanzieren des Grid Layouts mit dem namen Gr
GridLayout Gr = new GridLayout(1,3,5,5);
//setzen des GridLayouts mit hilfe von set Gilt nur f�r die panels p1 p2 p3 nicht f�r deren inhalt
setLayout (Gr);
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();

GridLayout Fl = new GridLayout(12,1,5,5);
GridLayout Fl2 = new GridLayout(1,1,5,5);

p1.setLayout(Fl);
p2.setLayout(Fl2);
p3.setLayout(Fl);
//Hintergrund Farbe f�r alle Panels
setBackground(Color.BLUE);
//oder Hintergrundfarbe f�r einzelne Panels
//p1.setBackground(Color.red);
//p2.setBackground(Color.blue);
//p3.setBackground(Color.yellow);
//Erzeugen der Label f�r die Textfelder
Label L1 = new Label("Name");
Label L2 = new Label("Vorname");
Label L3 = new Label("Strasse");
Label L4 = new Label("Hausnummer");
Label L5 = new Label("Ort");
Label L6 = new Label("PLZ");

TextField Namen = new TextField();
TextField Vorname = new TextField();
TextField Strasse = new TextField();
TextField Hausnummer = new TextField();
TextField Ort = new TextField();
TextField PLZ = new TextField();







TextArea Ausgabe = new TextArea("Hello Wie gehts",6,1);
Ausgabe.setRows(1);
Ausgabe.setEditable(false);
Ausgabe.setBackground(Color.blue);



Button B13 = new Button("�bernehmen");
Button B14 = new Button("Bearbeiten");
Button B15 = new Button("L�schen");
Button B16 = new Button("Ende");B16.addActionListener(new WindowLauscher());

//B13.addActionListener(new Display);
//B14.addActionListener(new Edit);
//B15.addActionListener(new Delete);



//Hinzuf�gen der Elemente zu den einzelnen Panels


p1.add (L1);p1.add(Namen);
p1.add (L2);p1.add(Vorname);
p1.add (L3);p1.add(Strasse);
p1.add (L4);p1.add(Hausnummer);
p1.add (L5);p1.add(Ort);
p1.add (L6);p1.add(PLZ);



p2.add(Ausgabe);
p3.add(B13);p3.add(B14);p3.add(B15);p3.add(B16);

add(p1);
add(p2);
add(p3);


addWindowListener(new WindowLauscher());
show();
}


//class Display implements ActionListener
//{
// String text = Namen.getText();
// Ausgabe.append(text + newline);
// Namen.selectAll();
//}

class WindowLauscher extends WindowAdapter

{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

}
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All I see is a bunch of unformatted code and no error messages or problem described.
It would be helpful if you would use the UBB Code Blocks to format your code. Also, it helps us help you if you tell us what the actual problem is. Also, if you are getting error message, you need to tell us what those are.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you implement ActionListener in your class, you don't need to create an internal class. All you have to do is implement the methods that ActionListener requires.

That is the gist of it.
 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is a more precise error message I get when compiling the file
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied to (formular2.WindowLauscher)
Button B16 = new Button("Ende");B16.addActionListener(new WindowLauscher());
It is probably only something I cant see please forgive my ignorance
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because your WindowLauscher class is not an ActionListener. It's a WindowAdapter.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gerhard
I see you have a window listener which is called when you close your app with the top right hand corner red cross.
What I think you are trying to do is close you app when you press the "ende" button.
You could implement the ActionListener interface in your WindowLauscher class and then it should compile ok.


Tell us how you get on!
 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you this works fine for me.
Are you interested helping me with another matter ?
If you are please read on
I am now trying to save the contents of Ausgabe but I am not sure if Iam using the right method
the Speichern is the save method
here is the changed code
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gerhard
You should start new questions in a new thread all together when they are not related enough to your original post. The question are you asking now doesn't belong in the SWING forum. It should be in the IO and Streams forum. However, I don't want to move this thread there since it started out as a SWING question. Please ask your ObjectOutputStream in the IO and Streams forum.
[ February 16, 2004: Message edited by: Gregg Bolinger ]
 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Problem I'll post it there.
I just thought I would be nice if you could follow a case right to the end.
Do you never sleep?
 
Gerhard Abrahams
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If anyone wants to follow this
Continued elsewhere
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic