这个例程的目的是将用户输入的用户名和密码和用户的登陆当前时间写到d:\\userlog.txt文件中
但是执行之后没有任何反应,感觉好象是按钮事件没有起作用,望高手指教,谢谢!!
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
* @author Administrator
*
*/
public class ATM extends JApplet implements ActionListener{
JLabel weclome,code,password;
JPanel p1;
JTextField textcode,textpassword;
JButton ok,exit;
GridLayout gb;
GridBagConstraints gbc;
Date date;
GregorianCalendar gcal;
public void init(){
p1=new JPanel();
p1=(JPanel)getContentPane();
gb=new GridLayout(2,3);
p1.setLayout(gb);
JLabel weclome=new JLabel("欢迎使用ATM综合服务模拟系统");
JLabel code=new JLabel("用户名");
JLabel password=new JLabel("密码");
JTextField textcode=new JTextField(16);
JTextField textpassword=new JTextField(16);
JButton ok=new JButton("登陆");
JButton exit=new JButton("退出");
p1.add(code);
p1.add(textcode);
p1.add(ok);
p1.add(password);
p1.add(textpassword);
p1.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
JButton source=(JButton)event.getSource();
if(source==ok){
date=new Date();
gcal=new GregorianCalendar();
gcal.setTime(date);
String entry="user:"+textcode.getText()+",password:"+textpassword.getText()+
"login in:"+gcal.get(Calendar.HOUR)+":"+gcal.get(Calendar.MINUTE)+":"+
"DATE:"+gcal.get(Calendar.MONTH)+"/"+gcal.get(Calendar.DATE)+"/"+
gcal.get(Calendar.YEAR);
try{
FileOutputStream foutputstream=new FileOutputStream("d:\\userlog.txt");
for(int i=0;i<entry.length();i++)
foutputstream.write(entry.charAt(i));
foutputstream.close();
System.out.println("已成功写入日志");
}catch(IOException e){
showStatus("不能写入日志"+e);
}
}
if(source==exit){
getAppletContext().showStatus("你点的是取消");
return;
}
}
}
但是执行之后没有任何反应,感觉好象是按钮事件没有起作用,望高手指教,谢谢!!
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
/**
* @author Administrator
*
*/
public class ATM extends JApplet implements ActionListener{
JLabel weclome,code,password;
JPanel p1;
JTextField textcode,textpassword;
JButton ok,exit;
GridLayout gb;
GridBagConstraints gbc;
Date date;
GregorianCalendar gcal;
public void init(){
p1=new JPanel();
p1=(JPanel)getContentPane();
gb=new GridLayout(2,3);
p1.setLayout(gb);
JLabel weclome=new JLabel("欢迎使用ATM综合服务模拟系统");
JLabel code=new JLabel("用户名");
JLabel password=new JLabel("密码");
JTextField textcode=new JTextField(16);
JTextField textpassword=new JTextField(16);
JButton ok=new JButton("登陆");
JButton exit=new JButton("退出");
p1.add(code);
p1.add(textcode);
p1.add(ok);
p1.add(password);
p1.add(textpassword);
p1.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
// TODO Auto-generated method stub
JButton source=(JButton)event.getSource();
if(source==ok){
date=new Date();
gcal=new GregorianCalendar();
gcal.setTime(date);
String entry="user:"+textcode.getText()+",password:"+textpassword.getText()+
"login in:"+gcal.get(Calendar.HOUR)+":"+gcal.get(Calendar.MINUTE)+":"+
"DATE:"+gcal.get(Calendar.MONTH)+"/"+gcal.get(Calendar.DATE)+"/"+
gcal.get(Calendar.YEAR);
try{
FileOutputStream foutputstream=new FileOutputStream("d:\\userlog.txt");
for(int i=0;i<entry.length();i++)
foutputstream.write(entry.charAt(i));
foutputstream.close();
System.out.println("已成功写入日志");
}catch(IOException e){
showStatus("不能写入日志"+e);
}
}
if(source==exit){
getAppletContext().showStatus("你点的是取消");
return;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货