我的程序显示它运行成功,但我的对话框不会出现。我是 Java 新手,我不确定我哪里出错了,有人可以帮忙吗?我正在尝试写入将存储用户输入的文件
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package database;
/**
*
*
*/
import java.io.*;
import java.awt.*;
import java.awt.event.*;
`enter code here`import javax.swing.*;
`public class Database extends JFrame implements ActionListener{
FlowLayout flow = new FlowLayout();
JLabel fName = new JLabel("First Name");
JTextField fName1 = new JTextField(15);
JLabel blankSpaces1 = new JLabel(" ");
JLabel lName = new JLabel("Last Name");
JTextField lName1 = new JTextField(15);
JLabel blankSpaces2 = new JLabel(" ");
JLabel age = new JLabel("Age");
JTextField age1 = new JTextField(3);
JLabel blankSpaces3 = new JLabel(" ");
JLabel email = new JLabel("Email Address");
JTextField email1 = new JTextField(30);
JLabel blankSpaces4 = new JLabel(" ");
JLabel phone = new JLabel("Cell Phone Number");
JTextField phone1 = new JTextField(10);
JLabel blankSpaces5 = new JLabel(" ");
JLabel blankSpaces6 = new JLabel(" ");
JButton enter = new JButton("Enter");
JButton reset = new JButton("Reset");
JButton exitButton = new JButton("Exit");
Container con = getContentPane();
public void Database (){
Database Dab = new Database();
con.setLayout(flow);
setTitle("Antwain's Database");
Dab.setSize(800,300);
setVisible(true);
con.add(fName);
con.add(blankSpaces1);
con.add(fName1);
con.add(blankSpaces1);
con.add(lName);
con.add(lName1);
con.add(blankSpaces2);
con.add(age);
con.add(age1);
con.add(blankSpaces3);
con.add(email);
con.add(email1);
con.add(blankSpaces4);
con.add(phone);
con.add(phone1);
con.add(blankSpaces5);
con.add(blankSpaces6);
con.add(blankSpaces2);
con.add(enter);
con.add(exitButton);
con.add(reset);
enter.addActionListener(this);
exitButton.addActionListener(this);
reset.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e1){
Object source = e1.getSource();
if(source == enter){
String fName = fName1.getText();
String lName = lName1.getText();
String age = age1.getText();
String email = email1.getText();
String phone = phone1.getText();
}
else
if(source == reset){
fName1.setText("");
lName1.setText("");
age1.setText("");
email1.setText("");
phone1.setText("");
}
else
{
// if the user clicks on the Exit button (source is Exit button)
System.exit(0);
}
}
public static void main(String[] args) {
Database dab = new Database();
}
}