确定。所以我正在尝试创建一个Login选项卡。它不会运行。它只是说“过程已完成”。有人? :)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Login extends JFrame implements ActionListener
{
JLabel User = new JLabel ("Username: ");
JTextField txtUser = new JTextField(20);
JLabel UserPass = new JLabel ("Password: ");
JPasswordField txtPass = new JPasswordField(20);
JLabel RemarksLabel = new JLabel();
JButton OK = new JButton ("OK");
JButton Cancel = new JButton ("Cancel");
Container c = getContentPane();
public Login()
{
c.setLayout (null);
c.setBackground(Color.GRAY);
c.add(User);
User.setForeground(Color.WHITE);
c.add(txtUser);
c.add(UserPass);
UserPass.setForeground(Color.WHITE);
c.add(txtPass);
c.add(RemarksLabel);
c.add(OK);
c.add(Cancel);
User.setBounds(10,20,80,20);
txtUser.setBounds(80,20,100,20);
UserPass.setBounds(10,45,80,20);
txtPass.setBounds(80,45,100,20);
OK.setBounds(70,70,55,20);
Cancel.setBounds(125,70,55,20);
txtPass.addActionListener(this);
OK.addActionListener(this);
Cancel.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
String userInput = txtUser.getText();
String passInput = txtPass.getText();
if (userInput.equals("Admin") && passInput.equals("admin"))
{
setVisible(true);
JOptionPane.showMessageDialog(null, "sdf");
}
else
{
RemarksLabel.setForeground(Color.red);
RemarksLabel.setFont(new Font("Tahoma", Font.BOLD, 12));
RemarksLabel.setText("Invalid Username/Password");
}
}
public static void main (String args[])
{
new Login();
}
}
答案 0 :(得分:0)
你必须出示你的窗口:
public static void main (String args[])
{
JFrame l = new Login();
l.setVisible(true);
// Or l.show();
}
查看http://docs.oracle.com/javase/7/docs/api/java/awt/Window.html#setVisible%28boolean%29