Tastatur frame nur nur 1 mal öffnen

Diskutiere Tastatur frame nur nur 1 mal öffnen im AWT, Swing, JavaFX & SWT Bereich.
S

Selmau

Hallo Zusammen

Ich programmiere eine Applikation, welche ich auf einem Windows Tablet ausführen möchte. Da dort aber die Tablet Tastatur nicht aufrufbar ist ( Problem von Windows) habe ich ein eigenes JFrame mit einer Tastatur drauf erstellt.

Nun öffne ich das Frame über einen MoseEvent im Textfeld. Da ich aber bei einem weiteren Textfeld das Frame aufgrund Schnittstellen zum neuen Textfeld erneut öffnen muss, möchte ich immer zuvor das alte Frame schliessen (ausser beim ersten Mal). Dafür wollte ich über die dispose() Methode das Frame aus einer anderen Klasse (diejenigen in der das Textfeld ist) schliessen. Leider funktioniert aber die dispose() Methode nicht.

Hier mein Code des Tastatur Frames:
Code:
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import java.awt.*;

public class keyboard_frame {

    public static  JFrame frame;
    public JButton btnNewButton;
 
 

    /**
     * Launch the application.
     */
    public  void keyboard_frame1(JTextField keyboard) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    keyboard_frame window = new keyboard_frame(keyboard);
                                 
                    window.frame.setVisible(true);
                 
                 
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public keyboard_frame(JTextField keyboard) {
     
        initialize( keyboard);
    }


    public keyboard_frame() {
        // TODO Auto-generated constructor stub
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize(JTextField keyboard) {
     
        frame = new JFrame();
        frame.setBounds(0, 10, 798, 439);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        frame.setAlwaysOnTop(true);
     
        JButton btnNewButton = new JButton("");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("", Home.keyboard_string, keyboard);
            }
        });
        btnNewButton.setForeground(Color.WHITE);
        btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnNewButton.setBackground(Color.DARK_GRAY);
        btnNewButton.setBounds(0, 320, 497, 80);
        frame.getContentPane().add(btnNewButton);
     
        JButton button = new JButton("Y");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("y", Home.keyboard_string, keyboard);
            }
        });
        button.setForeground(Color.WHITE);
        button.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button.setBackground(Color.DARK_GRAY);
        button.setBounds(0, 240, 72, 80);
        frame.getContentPane().add(button);
     
        JButton button_1 = new JButton("X");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("x", Home.keyboard_string, keyboard);
            }
        });
        button_1.setForeground(Color.WHITE);
        button_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_1.setBackground(Color.DARK_GRAY);
        button_1.setBounds(72, 240, 72, 80);
        frame.getContentPane().add(button_1);
     
        JButton button_2 = new JButton("C");
        button_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("c", Home.keyboard_string, keyboard);
            }
        });
        button_2.setForeground(Color.WHITE);
        button_2.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_2.setBackground(Color.DARK_GRAY);
        button_2.setBounds(143, 240, 72, 80);
        frame.getContentPane().add(button_2);
     
        JButton button_3 = new JButton("V");
        button_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("v", Home.keyboard_string, keyboard);
            }
        });
        button_3.setForeground(Color.WHITE);
        button_3.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_3.setBackground(Color.DARK_GRAY);
        button_3.setBounds(213, 240, 72, 80);
        frame.getContentPane().add(button_3);
     
        JButton btnB = new JButton("B");
        btnB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("b", Home.keyboard_string, keyboard);
            }
        });
        btnB.setForeground(Color.WHITE);
        btnB.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnB.setBackground(Color.DARK_GRAY);
        btnB.setBounds(284, 240, 72, 80);
        frame.getContentPane().add(btnB);
     
        JButton btnN = new JButton("N");
        btnN.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("n", Home.keyboard_string, keyboard);
            }
        });
        btnN.setForeground(Color.WHITE);
        btnN.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnN.setBackground(Color.DARK_GRAY);
        btnN.setBounds(355, 240, 72, 80);
        frame.getContentPane().add(btnN);
     
        JButton btnM = new JButton("M");
        btnM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("m", Home.keyboard_string, keyboard);
            }
        });
        btnM.setForeground(Color.WHITE);
        btnM.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnM.setBackground(Color.DARK_GRAY);
        btnM.setBounds(425, 240, 72, 80);
        frame.getContentPane().add(btnM);
     
        JButton button_7 = new JButton(",");
        button_7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key (",", Home.keyboard_string, keyboard);
            }
        });
        button_7.setForeground(Color.WHITE);
        button_7.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_7.setBackground(Color.DARK_GRAY);
        button_7.setBounds(497, 240, 72, 80);
        frame.getContentPane().add(button_7);
     
        JButton button_8 = new JButton(".");
        button_8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key (".", Home.keyboard_string, keyboard);
            }
        });
        button_8.setForeground(Color.WHITE);
        button_8.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_8.setBackground(Color.DARK_GRAY);
        button_8.setBounds(569, 240, 72, 80);
        frame.getContentPane().add(button_8);
     
        JButton button_9 = new JButton("-");
        button_9.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("-", Home.keyboard_string, keyboard);
            }
        });
        button_9.setForeground(Color.WHITE);
        button_9.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_9.setBackground(Color.DARK_GRAY);
        button_9.setBounds(639, 240, 72, 80);
        frame.getContentPane().add(button_9);
     
        JButton btnA_1 = new JButton("A");
        btnA_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("a", Home.keyboard_string, keyboard);
            }
        });
        btnA_1.setForeground(Color.WHITE);
        btnA_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnA_1.setBackground(Color.DARK_GRAY);
        btnA_1.setBounds(0, 160, 72, 80);
        frame.getContentPane().add(btnA_1);
     
        JButton btnS_1 = new JButton("S");
        btnS_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("s", Home.keyboard_string, keyboard);
            }
        });
        btnS_1.setForeground(Color.WHITE);
        btnS_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnS_1.setBackground(Color.DARK_GRAY);
        btnS_1.setBounds(72, 160, 72, 80);
        frame.getContentPane().add(btnS_1);
     
        JButton btnD = new JButton("D");
        btnD.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("d", Home.keyboard_string, keyboard);
            }
        });
        btnD.setForeground(Color.WHITE);
        btnD.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnD.setBackground(Color.DARK_GRAY);
        btnD.setBounds(143, 160, 72, 80);
        frame.getContentPane().add(btnD);
     
        JButton btnF = new JButton("F");
        btnF.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("f", Home.keyboard_string, keyboard);
            }
        });
        btnF.setForeground(Color.WHITE);
        btnF.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnF.setBackground(Color.DARK_GRAY);
        btnF.setBounds(213, 160, 72, 80);
        frame.getContentPane().add(btnF);
     
        JButton btnG = new JButton("G");
        btnG.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("g", Home.keyboard_string, keyboard);
            }
        });
        btnG.setForeground(Color.WHITE);
        btnG.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnG.setBackground(Color.DARK_GRAY);
        btnG.setBounds(284, 160, 72, 80);
        frame.getContentPane().add(btnG);
     
        JButton btnH = new JButton("H");
        btnH.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("h", Home.keyboard_string, keyboard);
            }
        });
        btnH.setForeground(Color.WHITE);
        btnH.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnH.setBackground(Color.DARK_GRAY);
        btnH.setBounds(355, 160, 72, 80);
        frame.getContentPane().add(btnH);
     
        JButton btnJ = new JButton("J");
        btnJ.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("j", Home.keyboard_string, keyboard);
            }
        });
        btnJ.setForeground(Color.WHITE);
        btnJ.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnJ.setBackground(Color.DARK_GRAY);
        btnJ.setBounds(425, 160, 72, 80);
        frame.getContentPane().add(btnJ);
     
        JButton btnK = new JButton("K");
        btnK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("k", Home.keyboard_string, keyboard);
            }
        });
        btnK.setForeground(Color.WHITE);
        btnK.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnK.setBackground(Color.DARK_GRAY);
        btnK.setBounds(497, 160, 72, 80);
        frame.getContentPane().add(btnK);
     
        JButton btnL = new JButton("L");
        btnL.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("l", Home.keyboard_string, keyboard);
            }
        });
        btnL.setForeground(Color.WHITE);
        btnL.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnL.setBackground(Color.DARK_GRAY);
        btnL.setBounds(569, 160, 72, 80);
        frame.getContentPane().add(btnL);
     
        JButton button_16 = new JButton("\u00F6");
        button_16.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("\u00F6", Home.keyboard_string, keyboard);
            }
        });
        button_16.setForeground(Color.WHITE);
        button_16.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_16.setBackground(Color.DARK_GRAY);
        button_16.setBounds(639, 160, 72, 80);
        frame.getContentPane().add(button_16);
     
        JButton btnA = new JButton("Q");
        btnA.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("q", Home.keyboard_string, keyboard);
            }
        });
        btnA.setForeground(Color.WHITE);
        btnA.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnA.setBackground(Color.DARK_GRAY);
        btnA.setBounds(0, 79, 72, 80);
        frame.getContentPane().add(btnA);
     
        JButton btnS = new JButton("W");
        btnS.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("s", Home.keyboard_string, keyboard);
            }
        });
        btnS.setForeground(Color.WHITE);
        btnS.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnS.setBackground(Color.DARK_GRAY);
        btnS.setBounds(72, 79, 72, 80);
        frame.getContentPane().add(btnS);
     
        JButton btnE = new JButton("E");
         btnE.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("e", Home.keyboard_string, keyboard);
            }
        });
        btnE.setForeground(Color.WHITE);
        btnE.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnE.setBackground(Color.DARK_GRAY);
        btnE.setBounds(143, 79, 72, 80);
        frame.getContentPane().add(btnE);
     
        JButton btnR = new JButton("R");
        btnR.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("r", Home.keyboard_string, keyboard);
            }
        });
        btnR.setForeground(Color.WHITE);
        btnR.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnR.setBackground(Color.DARK_GRAY);
        btnR.setBounds(213, 79, 72, 80);
        frame.getContentPane().add(btnR);
     
        JButton btnT = new JButton("T");
        btnT.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("t", Home.keyboard_string, keyboard);
            }
        });
        btnT.setForeground(Color.WHITE);
        btnT.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnT.setBackground(Color.DARK_GRAY);
        btnT.setBounds(284, 79, 72, 80);
        frame.getContentPane().add(btnT);
     
        JButton btnZ = new JButton("Z");
        btnZ.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("z", Home.keyboard_string, keyboard);
            }
        });
        btnZ.setForeground(Color.WHITE);
        btnZ.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnZ.setBackground(Color.DARK_GRAY);
        btnZ.setBounds(355, 79, 72, 80);
        frame.getContentPane().add(btnZ);
     
        JButton btnU = new JButton("U");
        btnU.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("u", Home.keyboard_string, keyboard);
            }
        });
        btnU.setForeground(Color.WHITE);
        btnU.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnU.setBackground(Color.DARK_GRAY);
        btnU.setBounds(425, 79, 72, 80);
        frame.getContentPane().add(btnU);
     

     
        JButton button_10 = new JButton("!");
        button_10.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("!", Home.keyboard_string, keyboard);
            }
        });
        button_10.setForeground(Color.WHITE);
        button_10.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_10.setBackground(Color.DARK_GRAY);
        button_10.setBounds(710, 240, 72, 80);
        frame.getContentPane().add(button_10);
     
        JButton button_11 = new JButton("/");
        button_11.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("/", Home.keyboard_string, keyboard);
            }
        });
        button_11.setForeground(Color.WHITE);
        button_11.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_11.setBackground(Color.DARK_GRAY);
        button_11.setBounds(710, 320, 72, 80);
        frame.getContentPane().add(button_11);
     
        JButton button_12 = new JButton("<----");
        button_12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                delete_any_key(Home.keyboard_string, keyboard);
            }
        });
        button_12.setForeground(Color.WHITE);
        button_12.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_12.setBackground(Color.DARK_GRAY);
        button_12.setBounds(497, 320, 214, 80);
        frame.getContentPane().add(button_12);
    }
    public void insert_key (String key, String string, JTextField textfield){
         Home.keyboard_string =string + key;
     
        textfield.setText(String.valueOf(Home.keyboard_string));
     
    }
 
    public void delete_any_key (String string, JTextField textfield){
    Home.keyboard_string = string.substring(0, string.length() -1);
    textfield.setText(String.valueOf(Home.keyboard_string));
 
 
    }
    public void close_frame(){
 
    //    WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        // Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
        frame.dispose();
         
         
     
 
 
    }
     
 
}
Java:
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.awt.event.ActionEvent;
import java.awt.event.*;
import java.awt.*;

public class keyboard_frame {

    public static  JFrame frame;
    public JButton btnNewButton;
 
 

    /**
     * Launch the application.
     */
    public  void keyboard_frame1(JTextField keyboard) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    keyboard_frame window = new keyboard_frame(keyboard);
                                 
                    window.frame.setVisible(true);
                 
                 
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public keyboard_frame(JTextField keyboard) {
     
        initialize( keyboard);
    }


    public keyboard_frame() {
        // TODO Auto-generated constructor stub
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize(JTextField keyboard) {
     
        frame = new JFrame();
        frame.setBounds(0, 10, 798, 439);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.getContentPane().setLayout(null);
        frame.setAlwaysOnTop(true);
     
        JButton btnNewButton = new JButton("");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("", Home.keyboard_string, keyboard);
            }
        });
        btnNewButton.setForeground(Color.WHITE);
        btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnNewButton.setBackground(Color.DARK_GRAY);
        btnNewButton.setBounds(0, 320, 497, 80);
        frame.getContentPane().add(btnNewButton);
     
        JButton button = new JButton("Y");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("y", Home.keyboard_string, keyboard);
            }
        });
        button.setForeground(Color.WHITE);
        button.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button.setBackground(Color.DARK_GRAY);
        button.setBounds(0, 240, 72, 80);
        frame.getContentPane().add(button);
     
        JButton button_1 = new JButton("X");
        button_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("x", Home.keyboard_string, keyboard);
            }
        });
        button_1.setForeground(Color.WHITE);
        button_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_1.setBackground(Color.DARK_GRAY);
        button_1.setBounds(72, 240, 72, 80);
        frame.getContentPane().add(button_1);
     
        JButton button_2 = new JButton("C");
        button_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("c", Home.keyboard_string, keyboard);
            }
        });
        button_2.setForeground(Color.WHITE);
        button_2.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_2.setBackground(Color.DARK_GRAY);
        button_2.setBounds(143, 240, 72, 80);
        frame.getContentPane().add(button_2);
     
        JButton button_3 = new JButton("V");
        button_3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("v", Home.keyboard_string, keyboard);
            }
        });
        button_3.setForeground(Color.WHITE);
        button_3.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_3.setBackground(Color.DARK_GRAY);
        button_3.setBounds(213, 240, 72, 80);
        frame.getContentPane().add(button_3);
     
        JButton btnB = new JButton("B");
        btnB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("b", Home.keyboard_string, keyboard);
            }
        });
        btnB.setForeground(Color.WHITE);
        btnB.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnB.setBackground(Color.DARK_GRAY);
        btnB.setBounds(284, 240, 72, 80);
        frame.getContentPane().add(btnB);
     
        JButton btnN = new JButton("N");
        btnN.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("n", Home.keyboard_string, keyboard);
            }
        });
        btnN.setForeground(Color.WHITE);
        btnN.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnN.setBackground(Color.DARK_GRAY);
        btnN.setBounds(355, 240, 72, 80);
        frame.getContentPane().add(btnN);
     
        JButton btnM = new JButton("M");
        btnM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("m", Home.keyboard_string, keyboard);
            }
        });
        btnM.setForeground(Color.WHITE);
        btnM.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnM.setBackground(Color.DARK_GRAY);
        btnM.setBounds(425, 240, 72, 80);
        frame.getContentPane().add(btnM);
     
        JButton button_7 = new JButton(",");
        button_7.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key (",", Home.keyboard_string, keyboard);
            }
        });
        button_7.setForeground(Color.WHITE);
        button_7.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_7.setBackground(Color.DARK_GRAY);
        button_7.setBounds(497, 240, 72, 80);
        frame.getContentPane().add(button_7);
     
        JButton button_8 = new JButton(".");
        button_8.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key (".", Home.keyboard_string, keyboard);
            }
        });
        button_8.setForeground(Color.WHITE);
        button_8.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_8.setBackground(Color.DARK_GRAY);
        button_8.setBounds(569, 240, 72, 80);
        frame.getContentPane().add(button_8);
     
        JButton button_9 = new JButton("-");
        button_9.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("-", Home.keyboard_string, keyboard);
            }
        });
        button_9.setForeground(Color.WHITE);
        button_9.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_9.setBackground(Color.DARK_GRAY);
        button_9.setBounds(639, 240, 72, 80);
        frame.getContentPane().add(button_9);
     
        JButton btnA_1 = new JButton("A");
        btnA_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("a", Home.keyboard_string, keyboard);
            }
        });
        btnA_1.setForeground(Color.WHITE);
        btnA_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnA_1.setBackground(Color.DARK_GRAY);
        btnA_1.setBounds(0, 160, 72, 80);
        frame.getContentPane().add(btnA_1);
     
        JButton btnS_1 = new JButton("S");
        btnS_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("s", Home.keyboard_string, keyboard);
            }
        });
        btnS_1.setForeground(Color.WHITE);
        btnS_1.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnS_1.setBackground(Color.DARK_GRAY);
        btnS_1.setBounds(72, 160, 72, 80);
        frame.getContentPane().add(btnS_1);
     
        JButton btnD = new JButton("D");
        btnD.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("d", Home.keyboard_string, keyboard);
            }
        });
        btnD.setForeground(Color.WHITE);
        btnD.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnD.setBackground(Color.DARK_GRAY);
        btnD.setBounds(143, 160, 72, 80);
        frame.getContentPane().add(btnD);
     
        JButton btnF = new JButton("F");
        btnF.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("f", Home.keyboard_string, keyboard);
            }
        });
        btnF.setForeground(Color.WHITE);
        btnF.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnF.setBackground(Color.DARK_GRAY);
        btnF.setBounds(213, 160, 72, 80);
        frame.getContentPane().add(btnF);
     
        JButton btnG = new JButton("G");
        btnG.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("g", Home.keyboard_string, keyboard);
            }
        });
        btnG.setForeground(Color.WHITE);
        btnG.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnG.setBackground(Color.DARK_GRAY);
        btnG.setBounds(284, 160, 72, 80);
        frame.getContentPane().add(btnG);
     
        JButton btnH = new JButton("H");
        btnH.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("h", Home.keyboard_string, keyboard);
            }
        });
        btnH.setForeground(Color.WHITE);
        btnH.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnH.setBackground(Color.DARK_GRAY);
        btnH.setBounds(355, 160, 72, 80);
        frame.getContentPane().add(btnH);
     
        JButton btnJ = new JButton("J");
        btnJ.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("j", Home.keyboard_string, keyboard);
            }
        });
        btnJ.setForeground(Color.WHITE);
        btnJ.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnJ.setBackground(Color.DARK_GRAY);
        btnJ.setBounds(425, 160, 72, 80);
        frame.getContentPane().add(btnJ);
     
        JButton btnK = new JButton("K");
        btnK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("k", Home.keyboard_string, keyboard);
            }
        });
        btnK.setForeground(Color.WHITE);
        btnK.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnK.setBackground(Color.DARK_GRAY);
        btnK.setBounds(497, 160, 72, 80);
        frame.getContentPane().add(btnK);
     
        JButton btnL = new JButton("L");
        btnL.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("l", Home.keyboard_string, keyboard);
            }
        });
        btnL.setForeground(Color.WHITE);
        btnL.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnL.setBackground(Color.DARK_GRAY);
        btnL.setBounds(569, 160, 72, 80);
        frame.getContentPane().add(btnL);
     
        JButton button_16 = new JButton("\u00F6");
        button_16.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("\u00F6", Home.keyboard_string, keyboard);
            }
        });
        button_16.setForeground(Color.WHITE);
        button_16.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_16.setBackground(Color.DARK_GRAY);
        button_16.setBounds(639, 160, 72, 80);
        frame.getContentPane().add(button_16);
     
        JButton btnA = new JButton("Q");
        btnA.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("q", Home.keyboard_string, keyboard);
            }
        });
        btnA.setForeground(Color.WHITE);
        btnA.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnA.setBackground(Color.DARK_GRAY);
        btnA.setBounds(0, 79, 72, 80);
        frame.getContentPane().add(btnA);
     
        JButton btnS = new JButton("W");
        btnS.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("s", Home.keyboard_string, keyboard);
            }
        });
        btnS.setForeground(Color.WHITE);
        btnS.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnS.setBackground(Color.DARK_GRAY);
        btnS.setBounds(72, 79, 72, 80);
        frame.getContentPane().add(btnS);
     
        JButton btnE = new JButton("E");
         btnE.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("e", Home.keyboard_string, keyboard);
            }
        });
        btnE.setForeground(Color.WHITE);
        btnE.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnE.setBackground(Color.DARK_GRAY);
        btnE.setBounds(143, 79, 72, 80);
        frame.getContentPane().add(btnE);
     
        JButton btnR = new JButton("R");
        btnR.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("r", Home.keyboard_string, keyboard);
            }
        });
        btnR.setForeground(Color.WHITE);
        btnR.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnR.setBackground(Color.DARK_GRAY);
        btnR.setBounds(213, 79, 72, 80);
        frame.getContentPane().add(btnR);
     
        JButton btnT = new JButton("T");
        btnT.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("t", Home.keyboard_string, keyboard);
            }
        });
        btnT.setForeground(Color.WHITE);
        btnT.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnT.setBackground(Color.DARK_GRAY);
        btnT.setBounds(284, 79, 72, 80);
        frame.getContentPane().add(btnT);
     
        JButton btnZ = new JButton("Z");
        btnZ.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("z", Home.keyboard_string, keyboard);
            }
        });
        btnZ.setForeground(Color.WHITE);
        btnZ.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnZ.setBackground(Color.DARK_GRAY);
        btnZ.setBounds(355, 79, 72, 80);
        frame.getContentPane().add(btnZ);
     
        JButton btnU = new JButton("U");
        btnU.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("u", Home.keyboard_string, keyboard);
            }
        });
        btnU.setForeground(Color.WHITE);
        btnU.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnU.setBackground(Color.DARK_GRAY);
        btnU.setBounds(425, 79, 72, 80);
        frame.getContentPane().add(btnU);
     
        JButton btnI = new JButton("I");
         btnI.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("i", Home.keyboard_string, keyboard);
            }
        });
        btnI.setForeground(Color.WHITE);
        btnI.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnI.setBackground(Color.DARK_GRAY);
        btnI.setBounds(497, 79, 72, 80);
        frame.getContentPane().add(btnI);
     
        JButton btnO = new JButton("O");
        btnO.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("o", Home.keyboard_string, keyboard);
            }
        });
        btnO.setForeground(Color.WHITE);
        btnO.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnO.setBackground(Color.DARK_GRAY);
        btnO.setBounds(569, 79, 72, 80);
        frame.getContentPane().add(btnO);
     
        JButton btnP = new JButton("P");
        btnP.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("p", Home.keyboard_string, keyboard);
            }
        });
        btnP.setForeground(Color.WHITE);
        btnP.setFont(new Font("Tahoma", Font.PLAIN, 32));
        btnP.setBackground(Color.DARK_GRAY);
        btnP.setBounds(639, 79, 72, 80);
        frame.getContentPane().add(btnP);
     
        JButton button_27 = new JButton("1");
        button_27.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("1", Home.keyboard_string, keyboard);
            }
        });
        button_27.setForeground(Color.WHITE);
        button_27.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_27.setBackground(Color.DARK_GRAY);
        button_27.setBounds(0, 0, 72, 80);
        frame.getContentPane().add(button_27);
     
        JButton button_28 = new JButton("2");
        button_28.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("2", Home.keyboard_string, keyboard);
            }
        });
        button_28.setForeground(Color.WHITE);
        button_28.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_28.setBackground(Color.DARK_GRAY);
        button_28.setBounds(72, 0, 72, 80);
        frame.getContentPane().add(button_28);
     
        JButton button_29 = new JButton("3");
        button_29.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("3", Home.keyboard_string, keyboard);
            }
        });
        button_29.setForeground(Color.WHITE);
        button_29.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_29.setBackground(Color.DARK_GRAY);
        button_29.setBounds(143, 0, 72, 80);
        frame.getContentPane().add(button_29);
     
        JButton button_30 = new JButton("4");
        button_30.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("4", Home.keyboard_string, keyboard);
            }
        });
        button_30.setForeground(Color.WHITE);
        button_30.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_30.setBackground(Color.DARK_GRAY);
        button_30.setBounds(213, 0, 72, 80);
        frame.getContentPane().add(button_30);
     
        JButton button_31 = new JButton("5");
        button_31.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("5", Home.keyboard_string, keyboard);
            }
        });
        button_31.setForeground(Color.WHITE);
        button_31.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_31.setBackground(Color.DARK_GRAY);
        button_31.setBounds(284, 0, 72, 80);
        frame.getContentPane().add(button_31);
     
        JButton button_32 = new JButton("6");
        button_32.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("6", Home.keyboard_string, keyboard);
            }
        });
        button_32.setForeground(Color.WHITE);
        button_32.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_32.setBackground(Color.DARK_GRAY);
        button_32.setBounds(355, 0, 72, 80);
        frame.getContentPane().add(button_32);
     
        JButton button_33 = new JButton("7");
        button_33.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("7", Home.keyboard_string, keyboard);
            }
        });
        button_33.setForeground(Color.WHITE);
        button_33.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_33.setBackground(Color.DARK_GRAY);
        button_33.setBounds(425, 0, 72, 80);
        frame.getContentPane().add(button_33);
     
        JButton button_34 = new JButton("8");
        button_34.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("8", Home.keyboard_string, keyboard);
            }
        });
        button_34.setForeground(Color.WHITE);
        button_34.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_34.setBackground(Color.DARK_GRAY);
        button_34.setBounds(497, 0, 72, 80);
        frame.getContentPane().add(button_34);
     
        JButton button_35 = new JButton("9");
        button_35.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("9", Home.keyboard_string, keyboard);
            }
        });
        button_35.setForeground(Color.WHITE);
        button_35.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_35.setBackground(Color.DARK_GRAY);
        button_35.setBounds(569, 0, 72, 80);
        frame.getContentPane().add(button_35);
     
        JButton button_36 = new JButton("0");
        button_36.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("0", Home.keyboard_string, keyboard);
            }
        });
        button_36.setForeground(Color.WHITE);
        button_36.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_36.setBackground(Color.DARK_GRAY);
        button_36.setBounds(639, 0, 72, 80);
        frame.getContentPane().add(button_36);
     
        JButton button_4 = new JButton("\u00E4");
        button_4.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("\u00E4", Home.keyboard_string, keyboard);
            }
        });
        button_4.setForeground(Color.WHITE);
        button_4.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_4.setBackground(Color.DARK_GRAY);
        button_4.setBounds(710, 160, 72, 80);
        frame.getContentPane().add(button_4);
     
        JButton button_5 = new JButton("\u00FC");
        button_5.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("\u00FC", Home.keyboard_string, keyboard);
            }
        });
        button_5.setForeground(Color.WHITE);
        button_5.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_5.setBackground(Color.DARK_GRAY);
        button_5.setBounds(710, 79, 72, 80);
        frame.getContentPane().add(button_5);
     
        JButton button_6 = new JButton("?");
        button_6.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("?", Home.keyboard_string, keyboard);
            }
        });
        button_6.setForeground(Color.WHITE);
        button_6.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_6.setBackground(Color.DARK_GRAY);
        button_6.setBounds(710, 0, 72, 80);
        frame.getContentPane().add(button_6);
     
        JButton button_10 = new JButton("!");
        button_10.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("!", Home.keyboard_string, keyboard);
            }
        });
        button_10.setForeground(Color.WHITE);
        button_10.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_10.setBackground(Color.DARK_GRAY);
        button_10.setBounds(710, 240, 72, 80);
        frame.getContentPane().add(button_10);
     
        JButton button_11 = new JButton("/");
        button_11.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                insert_key ("/", Home.keyboard_string, keyboard);
            }
        });
        button_11.setForeground(Color.WHITE);
        button_11.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_11.setBackground(Color.DARK_GRAY);
        button_11.setBounds(710, 320, 72, 80);
        frame.getContentPane().add(button_11);
     
        JButton button_12 = new JButton("<----");
        button_12.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                delete_any_key(Home.keyboard_string, keyboard);
            }
        });
        button_12.setForeground(Color.WHITE);
        button_12.setFont(new Font("Tahoma", Font.PLAIN, 32));
        button_12.setBackground(Color.DARK_GRAY);
        button_12.setBounds(497, 320, 214, 80);
        frame.getContentPane().add(button_12);
    }
    public void insert_key (String key, String string, JTextField textfield){
         Home.keyboard_string =string + key;
     
        textfield.setText(String.valueOf(Home.keyboard_string));
     
    }
 
    public void delete_any_key (String string, JTextField textfield){
    Home.keyboard_string = string.substring(0, string.length() -1);
    textfield.setText(String.valueOf(Home.keyboard_string));
 
 
    }
    public void close_frame(){
 
    //    WindowEvent winClosingEvent = new WindowEvent(this,WindowEvent.WINDOW_CLOSING);
        // Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
        frame.dispose();
         
         
     
 
 
    }
     
 
}
 
VfL_Freak

VfL_Freak

Moin,
Dafür wollte ich über die dispose() Methode das Frame aus einer anderen Klasse (diejenigen in der das Textfeld ist) schliessen. Leider funktioniert aber die dispose() Methode nicht.
Was heißt "funktioniert nicht" ?? :rolleyes:
Hab' mir jetzt den ganzen Code nicht angeschaut ... vielleicht sollten Du die relevanten Stellen mal näher bezeichnen!
WO rufst Du denn das bewußste 'dispose' auf?

VG Klaus
 
Thema: 

Tastatur frame nur nur 1 mal öffnen

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben