Domanda

quando clicco il OK in programma second.java, l'uscita del programma del programma. Voglio che non per uscire (dato che c'è un filo conduttore). Ho provato a rimuovere setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE) .

alt text


codice


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class second extends JFrame implements ActionListener {

JLabel enterName;
JTextField name;
JButton click;
String storeName;

public second(){

    setLayout(null);
    setSize(300,250);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    enterName = new JLabel("Enter Your Name: ");
    click = new JButton("Click");
    name = new JTextField();
    enterName.setBounds(60,30,120,30);
    name.setBounds(80,60,130,30);
    click.setBounds(100,190,60,30);
    click.addActionListener(this);
    add(click);
    add(name);
    add(enterName);

}

public void actionPerformed(ActionEvent e) {

    if(e.getSource() == click) {

        storeName = name.getText();
        JOptionPane.showMessageDialog(null, "Hello" + storeName);
        System.exit(0);
    }
}

public static void main(String args[]){

    second s = new second();
    s.setVisible(true);
}
}

Molte grazie

È stato utile?

Soluzione

È necessario rimuovere la linea System.exit(0);. Questo è tutto.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top