[Java] tabulatortaste

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von encud, 12. Februar 2007 .

Schlagworte:
  1. 12. Februar 2007
    tabulatortaste

    hallo!
    ich habe volgendes problem... bei einer java datei will ich, dass wenn ich den tabulator drücke, in nicht das nächse fenster komme sondern in das letzte...
    das der quelltext:
    HTML:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    
    public class Tabelle4 extends JFrame implements ActionListener
    {
     JButton btn;
     TextField tfName,tfVname, tfFile;
     ButtonGroup bg_mw;
     JComboBox cKlasse;
     JTable jtable = new JTable(90, 5);
     JScrollPane jspane = new JScrollPane(jtable);
     int s=0, z=1;
     String str, st, klasse, mw;
    
     BufferedWriter f;
     
     Tabelle4()
     {
     super("Schüler-Tabelle");
     Image icon = this.getToolkit().getImage("logoPGS.jpg");
     this.setIconImage(icon);
     this.setSize(700, 500);
     this.setLocation(50, 50);
     this.setBackground(Color.orange);
     this.getContentPane().setLayout(null);
    
     JLabel l = new JLabel("Name");
     l.setBounds(20, 50, 90, 25);
     this.add(l);
     l = new JLabel("Vorname");
     l.setBounds(20, 90, 90, 25);
     this.add(l);
     l = new JLabel("Klasse");
     l.setBounds(20, 210, 90, 25);
     this.add(l);
    
     tfName = new TextField("");
     tfName.setBounds(140, 50, 100, 25);
     this.getContentPane().add(tfName);
    
     tfVname = new TextField("");
     tfVname.setBounds(140, 90, 100, 25);
     this.getContentPane().add(tfVname);
    
     tfFile = new TextField("");
     tfFile.setBounds(340, 390, 100, 25);
     this.getContentPane().add(tfFile);
     
     bg_mw = new ButtonGroup();
     JRadioButton rb1 = new JRadioButton ("Junge",true);
     JRadioButton rb2 = new JRadioButton ("Mädchen",false);
     bg_mw.add(rb1);
     bg_mw.add(rb2);
     rb1.setActionCommand(rb1.getText());
     rb2.setActionCommand(rb2.getText());
     rb1.setBounds(140, 130, 100, 30);
     rb2.setBounds(140, 160, 100, 30);
     this.add(rb1);
     this.add(rb2);
     
     String[] sKlasse = {"5a","5b","5c","5d"};
     cKlasse = new JComboBox(sKlasse);
     cKlasse.setBounds(140, 210, 60, 25);
     this.add(cKlasse);
    
     btn = new JButton("Übernehmen");
     btn.setBounds(100, 390, 140, 25);
     this.getContentPane().add(btn);
     btn.addActionListener(this);
    
     btn = new JButton("Speichern");
     btn.setBounds(480, 390, 100, 25);
     this.getContentPane().add(btn);
     btn.addActionListener(this);
    
     JScrollPane sPane1 = new JScrollPane(jtable);
     sPane1.setLocation(280,50);
     sPane1.setSize(350, 300);
     this.getContentPane().add(sPane1);
    
     jtable.setValueAt("Name", 0, 0);
     jtable.setValueAt("Vorname", 0, 1);
     jtable.setValueAt("Geschlecht", 0, 2);
     jtable.setValueAt("Klasse", 0, 3);
    
     this.addWindowListener(new WindowAdapter()
     {
     public void windowClosing(WindowEvent we)
     {
     System.exit(0);
     }
     });
     }
    
    //////////////////////////////////////////////////////////////////////////////// 
    
     public static void main(String[] args)
     {
     Tabelle4 t = new Tabelle4();
     t.setVisible(true);
     }
    //////////////////////////////////////////////////////////////////////////////// 
    
     public void actionPerformed(ActionEvent ae)
     {
     if(ae.getActionCommand().equals("Übernehmen"))
     {
     ButtonModel selected = bg_mw.getSelection();
     mw = selected.getActionCommand();
    
     klasse = (String) cKlasse.getSelectedItem();
    
     jtable.setValueAt(tfName.getText(), z, 0);
     jtable.setValueAt(tfVname.getText(), z, 1);
     jtable.setValueAt(mw, z, 2);
     jtable.setValueAt(klasse, z, 3);
     z++;
     }
     else if(ae.getActionCommand().equals("Speichern"))
     {
     int j =0;
     str = tfFile.getText();
     try {
     f = new BufferedWriter(new FileWriter("d:\\Temp\\"+str+".txt"));
     while (j<z) {
     st = (String)jtable.getValueAt(j,0) + '\t'+ (String)jtable.getValueAt(j,1) +
     '\t'+ (String)jtable.getValueAt(j,2) + '\t'+ (String)jtable.getValueAt(j,3);
     f.write(st);
     f.newLine();
     j++;
     }
     f.close();
     } catch (IOException e) {
     System.out.println("Fehler beim Erstellen der Datei");
     }
     }
     }
    
    }
    währe echt geil wenn mir wer helfen könnte:]
    bewertung gibts für jeden versuch...
     
  2. 12. Februar 2007
    AW: tabulatortaste

    Mit dem KeyListener sollte es dir möglich sein den Tabulator abzufangen. Hab dir mal die Stelle aus der Doku rausgesucht.


    KeyListener (Java 2 Platform SE 5.0)
     
  3. 12. Februar 2007
    AW: tabulatortaste

    lol, danke schonmal, aber ihr müsst wissen, dass ich mich mit java nicht ganz so gut auskenne, und das für die schlue brauche... vllt hat ja wer nen plan wie man das in den quelltext einbauen könnte...

    bewertung is draußen!!!
     
  4. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.