ERLEDIGT
NEIN
NEIN
ANTWORTEN
9
9
ZUGRIFFE
450
450
EMPFEHLEN
-
Hallo habe ein kleine Problem,
immer wenn ich ein Java Progrämmchen starte und es dannach per Klich der Windows X Buttons schliese bleibt noch ein Prozess offen. Diese Stapeln sich dann bin zum erliegen des Systems. Was muss ich in mein Programm noch einfügen um dies zu verhindern?
Danke
-
12.04.05 20:10 #2
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
einfach mal setDefaultCloseOperation(EXIT_ON_CLOSE) z.Bsp. im Konstruktor eines JFrames aufrufen...
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
das habe ich schon drin ... trotzdem bleibt was übrig.
hier mal den code, falls das relevant ist:
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94
import java.awt.event.*; import javax.swing.*; public class RegionMatches extends JFrame implements ActionListener{ private JFrame frm; private JTextField txt1; private JTextField txt2; private JTextField txt3; private JTextField txt4; private JTextField txt5; private JButton btn1; private JLabel lbl; private JLabel lbl2; private JLabel lbl3; private JLabel lbl4; public RegionMatches() { frm = new JFrame("String charakteristik vergleichen ..."); frm.setLocation(100, 100); frm.setSize(450, 200); frm.setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); txt1 = new JTextField(); txt1.setLocation(20, 20); txt1.setSize(200,20); frm.add(txt1); txt2 = new JTextField(); txt2.setLocation(20, 50); txt2.setSize(200,20); frm.add(txt2); lbl2 = new JLabel("Index String1:"); lbl2.setLocation(20, 80); lbl2.setSize(100, 20); frm.add(lbl2); txt3 = new JTextField(); txt3.setLocation(110, 80); txt3.setSize(20,20); frm.add(txt3); lbl3 = new JLabel("Index String2:"); lbl3.setLocation(150, 80); lbl3.setSize(100, 20); frm.add(lbl3); txt4 = new JTextField(); txt4.setLocation(240, 80); txt4.setSize(20,20); frm.add(txt4); lbl4 = new JLabel("Anzahl der Chars:"); lbl4.setLocation(280, 80); lbl4.setSize(100, 20); frm.add(lbl4); txt5 = new JTextField(); txt5.setLocation(390, 80); txt5.setSize(20,20); frm.add(txt5); btn1 = new JButton("Vergleichen..."); btn1.setLocation(250, 20); btn1.setSize(150, 50); btn1.addActionListener((ActionListener) this); frm.add(btn1); lbl = new JLabel("blubb"); lbl.setLocation(20, 110); lbl.setSize(350, 20); frm.add(lbl); frm.setVisible(true); } public static void main(String[] args) { RegionMatches rgn = new RegionMatches(); } public void actionPerformed(ActionEvent ae) { String a = txt1.getText(); String b = txt2.getText(); boolean c = a.regionMatches(Integer.parseInt(txt3.getText()), b, Integer.parseInt(txt4.getText()), Integer.parseInt(txt5.getText())); String ausgabe = "Das Ergebniss des vergleichs ergibt: Die Strings sind " + ((c == true)? "gleich":"unterschiedlich"); lbl.setText(ausgabe); } }
-
12.04.05 20:31 #4
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.886
- Blog-Einträge
- 29
Hallo!
Wenn du genau hinschaust, dann wirst du sehen, dass du eigentlich zwei Frames baust.
Du setzt zwar bei einem EXIT_ON_CLOSE, jedoch wird dieser nicht mit setVisible(true) sichtbar gemacht... an dem anderen (sichtbaren) Frame hast du keine Schließlogik implementiert....
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
ah, danke für die antwort.
lösung also:
frm.setDefault ....
nur was du mit 2 frames meinst, glaube ich net ganz verstanden zu habenGeändert von Acki (12.04.05 um 20:45 Uhr)
-
Hallo,
du hast 2 Frames
Code :1
public class RegionMatches extends JFrame
Der 2. Frame wird nicht benötigt, wenn du es so machst, ist das ok:Code :1
frm = new JFrame("String charakteristik vergleichen ...");
Code :1 2 3 4 5 6 7 8
public RegionMatches() { setLocation(100,100); setSize(200,200); getContentPane().setLayout(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); txt1 = new JTextField(); getContentPane().add(txt1); .......Geändert von Bernd1984 (13.04.05 um 09:11 Uhr)
Gruss Bernd
Zitat von mAu
-
also ich habe im Konstruktor einen WindowListener
Code :1 2 3 4 5 6 7 8
//Code zum Schließen des Fensters addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } });
dann benötige ich keinen zweiten Frame. Welche Lösung nun eleganter ist weiß ich aber nicht.
MfG
illaX
-
aber rufe ich mit
Code :1
frm.set ......
nicht den erstem frame wieder auf? verstehe ich grad net.
-
Hallo,
schreib zu deinemeinfach noch einCode :1
frm.setVisible(true);
dazu, dann wirst du sehen, das du 2 Frames hast. Denn du erzeugst, wie oben beschrieben 2 Frames.Code :1
setVisible(true);
Hier dein Code mit einem Frame:
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 81 82 83 84 85 86 87 88 89 90 91
import java.awt.event.*; import javax.swing.*; public class RegionMatches extends JFrame implements ActionListener{ private JTextField txt1; private JTextField txt2; private JTextField txt3; private JTextField txt4; private JTextField txt5; private JButton btn1; private JLabel lbl; private JLabel lbl2; private JLabel lbl3; private JLabel lbl4; public RegionMatches() { super("String charakteristik vergleichen ..."); setLocation(100, 100); setSize(450, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); txt1 = new JTextField(); txt1.setLocation(20, 20); txt1.setSize(200,20); getContentPane().add(txt1); txt2 = new JTextField(); txt2.setLocation(20, 50); txt2.setSize(200,20); getContentPane().add(txt2); lbl2 = new JLabel("Index String1:"); lbl2.setLocation(20, 80); lbl2.setSize(100, 20); getContentPane().add(lbl2); txt3 = new JTextField(); txt3.setLocation(110, 80); txt3.setSize(20,20); getContentPane().add(txt3); lbl3 = new JLabel("Index String2:"); lbl3.setLocation(150, 80); lbl3.setSize(100, 20); getContentPane().add(lbl3); txt4 = new JTextField(); txt4.setLocation(240, 80); txt4.setSize(20,20); getContentPane().add(txt4); lbl4 = new JLabel("Anzahl der Chars:"); lbl4.setLocation(280, 80); lbl4.setSize(100, 20); getContentPane().add(lbl4); txt5 = new JTextField(); txt5.setLocation(390, 80); txt5.setSize(20,20); getContentPane().add(txt5); btn1 = new JButton("Vergleichen..."); btn1.setLocation(250, 20); btn1.setSize(150, 50); btn1.addActionListener((ActionListener) this); getContentPane().add(btn1); lbl = new JLabel("blubb"); lbl.setLocation(20, 110); lbl.setSize(350, 20); getContentPane().add(lbl); setVisible(true); } public static void main(String[] args) { RegionMatches rgn = new RegionMatches(); } public void actionPerformed(ActionEvent ae) { String a = txt1.getText(); String b = txt2.getText(); boolean c = a.regionMatches(Integer.parseInt(txt3.getText()), b, Integer.parseInt(txt4.getText()), Integer.parseInt(txt5.getText())); String ausgabe = "Das Ergebniss des vergleichs ergibt: Die Strings sind " + ((c == true)? "gleich":"unterschiedlich"); lbl.setText(ausgabe); } }Gruss Bernd
Zitat von mAu
-
nun werde es akzeptieren, vielleicht auch mal verstehen ...
habe da noch eine frage, wie kann man eigentlich eine methode (z.b. actionPerformed) abbrechen.
also wenn z.b. ein übergabe wert net passt. oder in dem fall so ein textfeld leer bleibt.
Code :1 2 3
if (a == ""){ -->stop, break, exit, die?<-- }
Ähnliche Themen
-
Verbindung zum MySql Server wird nicht geschlossen!
Von mimoun im Forum .NET DatenverwaltungAntworten: 5Letzter Beitrag: 18.05.10, 14:10 -
Outlook per Code Einloggen: Prozess wird sofort wieder geschlossen
Von DrMueller im Forum Visual Basic 6.0Antworten: 2Letzter Beitrag: 21.04.10, 16:24 -
AltovaXML_COM Prozess in Java beendet nicht
Von Velow im Forum JavaAntworten: 2Letzter Beitrag: 20.01.09, 15:38 -
ProcessBuilder - Prozess wird nicht beendet
Von Ashaman im Forum Java GrundlagenAntworten: 5Letzter Beitrag: 24.09.08, 14:16 -
Popup soll geschlossen werden wenn das Hauptfenster geschlossen wird.
Von LiebHabSchafi im Forum PHPAntworten: 3Letzter Beitrag: 06.10.05, 23:21





Zitieren

Login





