怎么用JAVA编程编写一个界面程序(急求!!!)

已举报 回答 关注
怎么用JAVA编程编写一个界面程序(急求!!!)
问在线客服
扫码问在线客服
  • 回答数

    5

  • 浏览数

    7,512

5个回答 默认排序
  • 默认排序
  • 按时间排序

已采纳
我下面写了一个,初始账号和密码是 nihao 5201314 你可以改或设置
import java.awt.*;
import java.awt.event.*;
class MyDow extends Frame implements ActionListener{
private Label lName,lPassword;
private TextField tName,tPassword;
private Button login,rest,exitout;
private Label login_clew;
private int count=0;
private String myName="nihao";
private String myPassword="5201314";
public void setMyNP(String n,String p){
myName=n;
myPassword=p;
}
public MyDow(String str){
super(str);
}
public void init(){
setLayout(null);
setSize(400,300);
setVisible(true);
setResizable(false);

lName=new Label("姓名");
lName.setBounds(50, 70, 60, 30);add(lName);
lPassword=new Label("密码");
lPassword.setBounds(50, 120, 60, 30);add(lPassword);
tName=new TextField("");
tName.setBounds(110, 70, 200, 30);add(tName);
tPassword=new TextField("");
tPassword.setBounds(110, 120, 200, 30);add(tPassword);
login=new Button("登录");
login.setBounds(90, 200, 60, 30);add(login);
rest=new Button("重输");
rest.setBounds(170, 200, 60, 30);add(rest);
exitout=new Button("退出");
exitout.setBounds(250,200,60,30);add(exitout);
login_clew=new Label("");

login.addActionListener(this);
rest.addActionListener(this);
exitout.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==login){
if(count<2){
if(tName.getText().equalsIgnoreCase(myName)&&tPassword.getText().equalsIgnoreCase(myPassword)){
removeAll();
add(login_clew);
add(exitout);
exitout.setLabel("确定");
login_clew.setBounds(160,120,200,30);
login_clew.setText("欢迎XX用户!");
exitout.setBounds(170,220,60,30);
}else{
add(login_clew);
login_clew.setBounds(90,160,200,30);
login_clew.setText("请输入正确的信息!");
count++;
}
}else{
add(login_clew);
login_clew.setBounds(90,160,200,30);
login_clew.setText("你输入的次数达到了3次,不能登录了!");
}
}else if(e.getSource()==exitout){
System.exit(1);
}else{
lName.setText("");
lPassword.setText("");
}
}
}
public class UserLogin {
public static void main(String args[]){
MyDow m=new MyDow("登录窗口");
m.init();
}
}

取消 评论
System.out.println("你好!");
取消 评论
用SWT做很简单滴
取消 评论
package org.leadfar; import java.awt.Color;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.Writer; import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;public class Note extends JFrame implementsActionListener, KeyListener { privateJPanel panel; privateFile file = null; privateJTextArea jt; publicNote() { init(); } publicvoid init() { this.setSize(400,400); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLocation(400,400); panel= new JPanel(); panel.setSize(400,400); panel.setLayout(newGridLayout(1, 1)); panel.setBackground(Color.white); //panel.setLocation(0, 100); jt= new JTextArea(); jt.setLineWrap(true); JScrollPanejsp = new JScrollPane(jt); jt.addKeyListener(this); panel.add(jsp); JMenuBarjmb = new JMenuBar(); jmb.setLayout(newFlowLayout(FlowLayout.LEFT)); JMenujm = new JMenu("菜单"); JMenuItemjmi1 = new JMenuItem("关闭 ctrl+e"); JMenuItemjmi2 = new JMenuItem("保存ctrl+s"); JMenuItemjmi3 = new JMenuItem("另存为"); JMenuItemjmi4 = new JMenuItem("打开ctrl+o"); jmi1.addActionListener(this); jmi2.addActionListener(this); jmi3.addActionListener(this); jmi4.addActionListener(this); jm.add(jmi4); jm.add(jmi2); jm.add(jmi3); jm.add(jmi1); jmb.add(jm); this.setJMenuBar(jmb); this.add(panel); this.setVisible(true); } publicstatic void main(String[] args) { newNote(); } @Override publicvoid actionPerformed(ActionEvent e) { Stringcmd = e.getActionCommand(); if("打开ctrl+o".equals(cmd)){ read(); } if("关闭ctrl+e".equals(cmd)) { System.exit(0); } if("保存ctrl+s".equals(cmd)){ save(); } if("另存为".equals(cmd)){ resave(); } } publicvoid read() { JFileChooserjfc = new JFileChooser(); jfc.showOpenDialog(jfc); file= jfc.getSelectedFile(); try{ if(file != null) { FileInputStreamin = new FileInputStream(file); InputStreamReaderipr = new InputStreamReader(in, "GBK"); BufferedReaderbf = new BufferedReader(ipr); Stringstr = ""; while((str=bf.readLine()) != null) { jt.append(str); } } }catch (FileNotFoundException e) { System.out.println("打开文件失败"); }catch (IOException e) { System.out.println("打开文件失败"); } } publicvoid save() { if(file == null) { JFileChooserjfc = new JFileChooser(); jfc.showSaveDialog(jfc); file= jfc.getSelectedFile(); if(file != null) { try{ file.createNewFile(); }catch (IOException e) { //TODO Auto-generated catch block e.printStackTrace(); } } } OutputStreamWriterout = null; if(file != null) { try{ FileOutputStreamfos= new FileOutputStream(file); out= new OutputStreamWriter(fos, "GBK"); out.write(jt.getText()); out.flush(); out.close(); }catch (IOException e) { //TODO Auto-generated catch block e.printStackTrace(); } } } publicvoid resave() { JFileChooserjfc = new JFileChooser(); jfc.showSaveDialog(jfc); file= jfc.getSelectedFile(); if(file != null) { try{ file.createNewFile(); }catch (IOException e) { //TODO Auto-generated catch block e.printStackTrace(); } } OutputStreamWriterout = null; if(file != null) { try{ FileOutputStreamfos= new FileOutputStream(file); out= new OutputStreamWriter(fos, "GBK"); out.write(jt.getText()); out.flush(); out.close(); }catch (IOException e) { //TODO Auto-generated catch block e.printStackTrace(); } } } @Override publicvoid keyTyped(KeyEvent e) { } @Override publicvoid keyPressed(KeyEvent e) { if(e.isControlDown() && e.getKeyCode() == 83) { save(); } } @Override publicvoid keyReleased(KeyEvent e) { //System.out.println(e.getKeyCode()); if(e.isControlDown() && e.getKeyCode() == 69) { System.exit(0); } if(e.isControlDown() && e.getKeyCode() == 79) { read(); } } }这是我曾经写的一个java记事本的程序,你要的东西里边包含了,你试试看!
取消 评论
java 的simpledateformat类
取消 评论
ZOL问答 > 怎么用JAVA编程编写一个界面程序(急求!!!)

举报

感谢您为社区的和谐贡献力量请选择举报类型

举报成功

经过核实后将会做出处理
感谢您为社区和谐做出贡献

扫码参与新品0元试用
晒单、顶楼豪礼等你拿

扫一扫,关注我们
提示

确定要取消此次报名,退出该活动?