String username = this.name.getText();
String password = this.password.getText();
String message = username + " "+password;
try
{
byte[] b = message.getBytes();
FileOutputStream fos = new FileOutputStream("login.txt");
fos.write(b,0,b.length);
this.dispose();
}catch(Exception ex)
{
}
}
}
public static void main(String args[])
{
new login().show();
}
}
6. java如何写这个图形界面 //自己在微调一下坐标吧..import java.awt.BorderLayout;import java.awt.GridLayout;import java.awt.Rectangle;import java.io.Serializable;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;public class SwingTest extends JFrame implements Serializable{ private JPanel jp1,jp2,jp3; private JLabel ab1; private But[] list=But.values(); private static final long serialVersionUID = 1L; SwingTest(){ this.setTitle("系统首页"); this.setBounds(300, 300, 280, 200); this.setResizable(false); init(); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setVisible(true); } private void init() { jp1=new JPanel(); jp1.add(new JLabel("欢迎你来到图书馆租借系统")); jp2=new JPanel(null); ab1=new JLabel("请选择服务项目"); ab1.setBounds(new Rectangle(0, 0, 220, 25)); jp2.add(ab1); jp3=new JPanel(new GridLayout(6,1)); jp3.setBounds(80, 20, 120, 120); for (int i = 0; i jp3.add(new JButton(list[i].toString())); } jp2.add(jp3); this.add(jp1,BorderLayout.NORTH); this.add(jp2,BorderLayout.CENTER); } public static void main(String[] args) { new SwingTest(); } enum But{ 馆藏查询 , 节约查询 , 欠费查询 , 借书登记 , 还书登记 , 退出系统; }} 。
7. JAVA中登录窗口设计,源代码该怎么写 import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Test_Login extends javax.swing.JFrame {private JPanel jPanel1;private JButton bntLogin;private JButton bntCannel;private JPasswordField pwd;private JTextField username;private JLabel jLabel2;private JLabel jLabel1;public static void main(String[] args) { Test_Login inst = new Test_Login(); inst.setLocationRelativeTo(null); inst.setVisible(true);}public Test_Login() { super(); initGUI();}private void initGUI() { try { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jPanel1 = new JPanel(); getContentPane().add(jPanel1, BorderLayout.CENTER); jPanel1.setLayout(null); { jLabel1 = new JLabel(); jPanel1.add(jLabel1); jLabel1.setText("用户名"); jLabel1.setBounds(45, 30, 75, 25); } { jLabel2 = new JLabel(); jPanel1.add(jLabel2); jLabel2.setText("密码"); jLabel2.setBounds(45, 75, 55, 15); } { username = new JTextField(); jPanel1.add(username); username.setBounds(100, 30, 140, 25); } { pwd = new JPasswordField(); jPanel1.add(pwd); pwd.setBounds(100, 70, 140, 25); } { bntLogin = new JButton(); jPanel1.add(bntLogin); bntLogin.setText("登陆"); bntLogin.setBounds(40, 120, 60, 30); bntLogin.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (username.getText().equals("lisong") && pwd.getText().equals("lisong")) { JOptionPane.showMessageDialog(Test_Login.this , "登录成功"); } else { JOptionPane.showMessageDialog(Test_Login.this , "登录失败"); } } }); bntCannel = new JButton(); jPanel1.add(bntCannel); bntCannel.setText("取消"); bntCannel.setBounds(180, 120, 60, 30); bntCannel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.exit(0); } }); } } pack(); setSize(300, 215); } catch (Exception e) { e.printStackTrace(); }}} 。
8. 怎么用java编写一个按钮界面 效果图:参考代码如下import java.awt.*;import java.awt.event.*;import javax.swing.*;public class KeyDemo extends JFrame{ int index; JLabel jl = new JLabel("你好啊~"); JButton jb = new JButton("点击改变标签上的文字"); public KeyDemo() { //设置界面的布局为边界布局 this.setLayout(new BorderLayout()); //设置标签文字的位置在 布局的中间 this.add(jl, BorderLayout.CENTER); //设置按钮在布局的南部 this.add(jb, BorderLayout.SOUTH); //设置窗口的位置和大小 this.setBounds(350, 100, 200, 120); //设置窗口的关闭事件的响应 , 如果点击关闭按钮 , 那么就退出 this.setDefaultCloseOperation(EXIT_ON_CLOSE); //设置窗口的标题 this.setTitle("窗口"); //设置窗口是否可见 this.setVisible(true); //为按钮注册事件响应 , 有了这句代码就能让按钮能够响应点击事件了 jb.addActionListener(new MyActionListener()); } public static void main(String[] args) { //实例化窗口对象 new KeyDemo(); } //实现动作Listener接口 。
