所属课程、题目内容、题目选项、题目答案、题目等级、学生管理、试卷管理、题目管理、时间控制
public class ChangePasswordFrame extends javax.swing.JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
//注入
private UserManage userManage=new UserManageImp();
private JPanel jPanel1;
private JButton jButton1;
private JLabel jLabel5;
private JPasswordField jPasswordField2;
private JPasswordField jPasswordField1;
private JTextField jTextField2;
private JLabel jLabel4;
private JLabel jLabel3;
private JLabel jLabel1;
private JLabel jLabel2;
private JButton jButton2;
{
//Set Look & Feel
try {
javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ChangePasswordFrame inst = new ChangePasswordFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public ChangePasswordFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
{
jPanel1 = new JPanel();
getContentPane().add(jPanel1);
jPanel1.setBounds(0, 0, 485, 343);
jPanel1.setLayout(null);
{
jButton1 = new JButton();
jPanel1.add(jButton1);
jButton1.setText("\u786e\u8ba4");
jButton1.setBounds(182, 261, 52, 30);
}
{
jButton2 = new JButton();
jPanel1.add(jButton2);
jButton2.setText("\u91cd\u7f6e");
jButton2.setBounds(282, 261, 52, 30);
jButton2.setOpaque(true);
}
{
jLabel2 = new JLabel();
jPanel1.add(jLabel2);
jLabel2.setText(" \u4fee\u6539\u5bc6\u7801");
jLabel2.setBounds(140, 20, 203, 45);
jLabel2.setOpaque(true);
jLabel2.setFont(new java.awt.Font("楷体",0,18));
}
{
jLabel1 = new JLabel();
jPanel1.add(jLabel1);
jLabel1.setText("\u8f93\u5165\u5b66\u53f7");
jLabel1.setBounds(93, 88, 77, 18);
}
{
jLabel3 = new JLabel();
jPanel1.add(jLabel3);
jLabel3.setText("\u8f93\u5165\u5b66\u53f7");
jLabel3.setBounds(93, 88, 77, 18);
}
{
jLabel4 = new JLabel();
jPanel1.add(jLabel4);
jLabel4.setText("\u8f93\u5165\u65b0\u5bc6\u7801");
jLabel4.setBounds(93, 198, 77, 18);
}
{
jTextField2 = new JTextField();
jPanel1.add(jTextField2);
jTextField2.setBounds(182, 82, 146, 30);
}
{
jLabel5 = new JLabel();
jPanel1.add(jLabel5);
jLabel5.setText("\u8f93\u5165\u539f\u5bc6\u7801");
jLabel5.setBounds(93, 142, 77, 18);
}
{
jPasswordField1 = new JPasswordField();
jPanel1.add(jPasswordField1);
jPasswordField1.setBounds(182, 140, 147, 28);
}
{
jPasswordField2 = new JPasswordField();
jPanel1.add(jPasswordField2);
jPasswordField2.setBounds(182, 189, 147, 28);
}
}
pack();
this.setSize(501, 376);
setLocationRelativeTo(null);
setVisible(true);
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stube
int uid=Integer.parseInt(jTextField2.getText());
String password=new String(jPasswordField1.getPassword());
User user=userManage.findById(uid);
if(password.equals(user.getPassword())){
String newPassword=new String(jPasswordField2.getPassword());
user.setPassword(newPassword);
userManage.update(user);
JOptionPane.showMessageDialog(ChangePasswordFrame.this,"恭喜:"+user.getName()+"你的密码修改成功");
}
else
JOptionPane.showMessageDialog(jButton1, "原始密码错误");
}
});
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jPasswordField1.setText("");
jPasswordField2.setText("");
}
});
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
}
@SuppressWarnings("serial")
public class LoginFrame extends javax.swing.JFrame {
{
// Set Look & Feel
try {
javax.swing.UIManager
.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
}
private UserManage userManage = new UserManageImp();
/** Creates new form LoginFrame */
public LoginFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// GEN-BEGIN:initComponents
//
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
GroupLayout jPanel1Layout = new GroupLayout((JComponent) jPanel1);
jPanel1.setLayout(jPanel1Layout);
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
// setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
// 固定大小
setResizable(false);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int var = JOptionPane.showConfirmDialog(LoginFrame.this,
"确定离开吗?");
if (var == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
});
jButton1.setText("确认");
// 添加登陆事件 ,登陆 判断用户名和密码
jButton1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int uid = Integer.parseInt(jTextField1.getText());
String passwordInfo = new String(jPasswordField1
.getPassword());
if (null == jTextField1.getText() || null == passwordInfo) {
JOptionPane.showMessageDialog(LoginFrame.this, "请输入用户名和密码");
}
User user = userManage.findById(uid);
// System.out.println(user.getName());
String password = user.getPassword();
// System.out.println(MD5Util.md5(passwordInfo).equals(password));
if (passwordInfo.equals(password)) {
setVisible(false);
if ("admin".equals(user.getName())) {
JOptionPane
.showMessageDialog(LoginFrame.this, "welcome admin");
new ServerClient();
} else {
String name = userManage.findById(uid).getName();
JOptionPane.showMessageDialog(LoginFrame.this, "welcome "
+ name);
new WelcomeFrame(uid);
}
} else
JOptionPane.showMessageDialog(LoginFrame.this, "用户名不存在获密码错误");
}
});
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new ChangePasswordFrame();
}
});
// 请空密码和用户名
jButton2.setText("\u4fee\u6539\u5bc6\u7801");
jButton2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jTextField1.setText("");
}
});
jLabel1.setFont(new java.awt.Font("微软雅黑", 0, 18));
jLabel1.setText(" \u767b\u9646\u754c\u9762");
{
jPasswordField1 = new JPasswordField();
}
jLabel2.setText("编号");
jLabel3.setText("密码");
jTextField1.setFont(new java.awt.Font("Dotum", 0, 14));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(43).addGroup(
jPanel1Layout.createParallelGroup(
GroupLayout.Alignment.BASELINE).addComponent(
jTextField1, GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE).addComponent(
jLabel2, GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)).addGap(24)
.addGroup(
jPanel1Layout.createParallelGroup(
GroupLayout.Alignment.BASELINE).addComponent(
jPasswordField1,
GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE).addComponent(
jLabel3, GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)).addGap(55)
.addGroup(
jPanel1Layout.createParallelGroup(
GroupLayout.Alignment.BASELINE).addComponent(
jButton1, GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE).addComponent(
jButton2, GroupLayout.Alignment.BASELINE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)).addContainerGap(
92, 92));
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createSequentialGroup()
.addContainerGap(92, 92)
.addGroup(
jPanel1Layout
.createParallelGroup()
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGroup(
jPanel1Layout
.createParallelGroup()
.addComponent(
jLabel3,
GroupLayout.Alignment.LEADING,
GroupLayout.PREFERRED_SIZE,
43,
GroupLayout.PREFERRED_SIZE)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addGap(
0,
0,
Short.MAX_VALUE)
.addComponent(
jLabel2,
GroupLayout.PREFERRED_SIZE,
43,
GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(
LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
jPanel1Layout
.createParallelGroup()
.addComponent(
jPasswordField1,
GroupLayout.Alignment.LEADING,
GroupLayout.PREFERRED_SIZE,
161,
GroupLayout.PREFERRED_SIZE)
.addComponent(
jTextField1,
GroupLayout.Alignment.LEADING,
GroupLayout.PREFERRED_SIZE,
161,
GroupLayout.PREFERRED_SIZE)
.addGroup(
GroupLayout.Alignment.LEADING,
jPanel1Layout
.createSequentialGroup()
.addComponent(
jLabel1,
GroupLayout.PREFERRED_SIZE,
156,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
LayoutStyle.ComponentPlacement.RELATED,
0,
GroupLayout.PREFERRED_SIZE)))
.addGap(27))
.addGroup(
GroupLayout.Alignment.LEADING,
jPanel1Layout
.createSequentialGroup()
.addGap(23)
.addComponent(
jButton1,
GroupLayout.PREFERRED_SIZE,
71,
GroupLayout.PREFERRED_SIZE)
.addGap(0, 70,
Short.MAX_VALUE)
.addComponent(
jButton2,
GroupLayout.PREFERRED_SIZE,
79,
GroupLayout.PREFERRED_SIZE)))
.addContainerGap(116, 116));
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(
jPanel1, 0, 317, Short.MAX_VALUE));
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(
jPanel1, 0, 441, Short.MAX_VALUE));
pack();
this.setSize(457, 355);
// 置中
this.setLocationRelativeTo(null);
this.setVisible(true);
}//
// GEN-END:initComponents
private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new LoginFrame().setVisible(true);
}
});
}
// 得到输入量 匹配用户名和密码
public static String getNameAndPassword(String str, String str1)
throws IOException {
InputStreamReader is = new InputStreamReader(new FileInputStream(
new File("user.txt")));
BufferedReader br = new BufferedReader(is);
String line;
while (null != (line = br.readLine())) {
String[] np = line.split(":");
if (str.equals(np[0]) && str1.equals(np[2])) {
return np[1];
}
}
is.close();
return null;
}
// GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private JPasswordField jPasswordField1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
@SuppressWarnings("serial")
public class WelcomeFrame extends JWindow {
private PaperManage paperManage=new PaperManageImp();
private UserManage userManage=new UserManageImp();
int uid;
public WelcomeFrame(int uid) {
init();
this.uid=uid;
}
private void init() {
setSize(800, 470);
setContentPane(createContentPane());
Toolkit tool = Toolkit.getDefaultToolkit();
Dimension win = tool.getScreenSize();
int x = (int) (win.getWidth() / 2 - this.getWidth() / 2);
int y = (int) (win.getHeight() / 2 - this.getHeight() / 2);
this.setLocation(x, y);
this.setVisible(true);
//System.out.println(this instanceof WelcomeFrame);
new Thread() {
public void run() {
try {
Thread.sleep(3000);
setVisible(false);
if(paperManage.findById(uid).getListAnswer()==null){
new ExamClient(uid);
}
else{
Paper p=paperManage.findById(uid);
JOptionPane.showMessageDialog(WelcomeFrame.this, userManage.findById(uid).getName()+" 你已经考完"+p.getCourse()+",得分为:"+p.getUserPoint());
}
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
}
private JPanel createContentPane() {
JPanel p = new JPanel();
JLabel l = new JLabel();
p.setBorder(new LineBorder(Color.gray));
l.setIcon(new ImageIcon(getClass().getResource("exam1.jpg")));
p.add(l);
return p;
}
}