ERLEDIGT
JA
JA
ANTWORTEN
3
3
ZUGRIFFE
441
441
EMPFEHLEN
-
Hi,
ich habe ein Menuauswahl. Wenn ich einen der Menüpunkte anklicke, dann öffnet sich ein kleines Fenter, das unter anderem auch einen Ende-Button beinhaltet. Wenn ich diesen anklicke wird
System.exit( 0 );
aufgerufen. Damit wird aber das gesamte Programm beendet Ich will aber das Hauptfenster mit dem Menü weiterlaufen lassen und nur diesen Unterpunkt beenden. Wenn ich in dem kleinen Fenster das Schließen-Symbol anklicke verwende ich
win.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Damit wird nur das kleine Fenster beendet und das menü läuftt weiter. Wie erreiche ich das auch bei meinem Ende-Button?
Danke
Heiner
-
09.10.08 11:37 #2Code java:
1
window.dispose();
javaDoc ist dein Freund
REINHAUN!In theory, there is no difference between theory and practice. In practice, there is!
www.olivergierke.de
-
Danke für die Antwort:
Leider erhalte ich eine Fehlermenldung wenn ich das so mache. Hier mal der Code:
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
public void init_window() { JFrame win = new julianisch(400,180); win.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); win.setTitle("Berechnet Julianisches Datum"); Panel panel1 = new Panel(); panel1.setBackground(Color.BLACK); panel1.setLayout(new GridLayout(3,2)); JLabel L1 = new JLabel("Jahreszahl:"); JLabel L2 = new JLabel("Monat:"); JLabel L3 = new JLabel("Tag:"); JLabel L4 = new JLabel("Ergebnis:"); L1.setFont(new Font("Serif",Font.BOLD,20)); L1.setForeground(Color.MAGENTA); L2.setFont(new Font("Serif",Font.BOLD,20)); L2.setForeground(Color.MAGENTA); L3.setFont(new Font("Serif",Font.BOLD,20)); L3.setForeground(Color.MAGENTA); L4.setFont(new Font("Serif",Font.BOLD,20)); L4.setForeground(Color.RED); JButton BEnd = new JButton("Ende"); BEnd.setActionCommand("B1"); JButton BRech = new JButton("Berechnen"); BRech.setActionCommand("B2"); panel1.add(L1); panel1.add(TJahr); panel1.add(L2); panel1.add(TMonat); panel1.add(L3); panel1.add(TTag); Panel panel2 = new Panel(); panel2.setLayout(new GridLayout(1,1)); panel2.add(L4); panel2.add(TErg); Panel panel3 = new Panel(); panel3.setLayout(new BorderLayout()); panel3.add(BRech, BorderLayout.WEST); panel3.add(BEnd, BorderLayout.EAST); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("B1")) { win.dispose(); } if(e.getActionCommand().equals("B2")) { BerechneJulDatum(); } } }; BEnd.addActionListener(al); BRech.addActionListener(al); Panel panel4 = new Panel(); panel4.setLayout(new BoxLayout(panel4,BoxLayout.PAGE_AXIS)); panel4.add(panel1); panel4.add(panel2); panel4.add(panel3); win.setLayout(new GridLayout(1,1)); win.add(panel4); // win.pack(); win.setVisible( true ); }
Die meldung lautet:
cannot refer to non-final variable win inside a inner class defined in a differend method.
-
09.10.08 12:55 #4
Jo, und was sagt dir das? win muss final sein, damit du in der anonymen Klasse darauf zugreifen kannst.
Gruß
OllieIn theory, there is no difference between theory and practice. In practice, there is!
www.olivergierke.de
Ähnliche Themen
-
Unterprogramm
Von mafu im Forum .NET Windows FormsAntworten: 4Letzter Beitrag: 02.02.09, 20:18 -
Unterprogramm mit Arrays
Von martin5 im Forum C/C++Antworten: 4Letzter Beitrag: 27.12.08, 16:38 -
Unterprogramm mit Arrays
Von martin5 im Forum C/C++Antworten: 1Letzter Beitrag: 26.12.08, 00:33 -
Unterprogramm aufruf
Von Dorschty im Forum VisualStudio & MFCAntworten: 2Letzter Beitrag: 01.06.07, 13:50 -
Unterprogramm aufrufen
Von 5Rad im Forum Visual Basic 6.0Antworten: 3Letzter Beitrag: 14.05.07, 16:11





Zitieren
Login





