如何用JAVA编程编写一个界面程序(急求!!!)

急求JAVA编程,设计一个简单界面!~

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.net.*; import java.io.IOException; import java.io.*; public class chat { public static void main(String[] args) { new UDPMessage(); } } class UDPMessage extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = 1L; private JTextArea recordText = new JTextArea(); private JTextArea sendText = new JTextArea(); private DatagramSocket ds; private JButton btnSend = new JButton("发送"); private JButton btnExit = new JButton("关闭"); private JLabel otherTips = new JLabel("对方IP"); private JTextField otherIp = new JTextField(); private JLabel myTips = new JLabel("我的IP"); private JTextArea myIp = new JTextArea(); InputStreamReader in; //创建一个文件输入流 OutputStreamWriter out; //创建一个文件输出流 Container p; JScrollPane jspRecord; JMenuBar mb = new JMenuBar(); JMenu[] m = {new JMenu("文件"), new JMenu("好友"), new JMenu("背景")}; JMenuItem[][] mi = {{new JMenuItem("传送文件")}, {new JMenuItem("Regina"),new JMenuItem("Taotao"),new JMenuItem("LiShuo")}, {new JMenuItem("默 认"),new JMenuItem("浅灰色"),new JMenuItem("淡紫色"),new JMenuItem("黄绿色")}}; public UDPMessage() { super("HiChat"); p = getContentPane(); setSize(550, 475); centerOnScreen(); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); for(int i=0; i<m.length; i++) { mb.add(m[i]); for(int j=0; j<mi[i].length; j++) { m[i].add(mi[i][j]); mi[i][j].addActionListener(this); } } setJMenuBar(mb); p.setBackground(new Color(218, 112, 214)); p.setLayout(null); recordText.setEditable(false); recordText.setLineWrap(true); jspRecord = new JScrollPane(recordText); jspRecord.setBounds(2, 5, 350, 270); p.add(jspRecord); sendText.setLineWrap(true); JScrollPane jspSend = new JScrollPane(sendText); jspSend.setBounds(2, 285, 350,100); p.add(jspSend); btnExit.setBounds(184,390,80,25); btnExit.setMargin(new Insets(0, 0, 0, 0)); btnExit.addActionListener(this); p.add(btnExit); btnSend.setBounds(271,390,80,25); btnSend.setMargin(new Insets(0, 0, 0, 0)); btnSend.addActionListener(this); p.add(btnSend); GridLayout gl = new GridLayout(2, 0); gl.setVgap(15); JPanel infoPane = new JPanel(gl); infoPane.setOpa

package gui.test;//包名import javax.swing.JFrame;//导入需要的窗口包JFrameimport javax.swing.JLabel;//导入需要的标签包JLabelpublic class MainFrame extends JFrame{//构造方法进行初始化窗口public MainFrame(){JLabel jl = new JLabel();//创建一个标签jl.setText("Hello World");//标签上的文字叫Hello World//下面的this都指的是本窗口.都可以省略this.add(jl);//窗口添加刚刚创建的标签this.setTitle("窗口标题");//窗口的标题名字this.setLocation(300, 200);//窗口的左顶点在屏幕上的位置this.setSize(200, 220);//窗口是 宽200像素, 长220像素this.setDefaultCloseOperation(EXIT_ON_CLOSE);//设置窗口被关闭时候就退出窗口this.setVisible(true);//设置这个窗口能否被看见}public static void main(String[] args) {new MainFrame();//调用构造方法,创建一个窗口}}

我下面写了一个,初始账号和密码是 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();

    }

}



用swing组件来做,你可以用jbulid或则jcreate做为开发环境

用SWT做很简单滴

用java图形用户界面实现: 编写一个日历程序,能实现显示日历等简单功能...
答:month=1;} public Calender(int year){ this.year=year;month=1;} public Calender(int year,int month){ this.year=year;if(month>12)this.month=month%12;else this.month=month;} public void setYear(int year){ this.year=year;} public void setMonth(int month){ if(month>12)this....

...数字加1,例如点击了4次,则显示4。用C++或JAVA学什么?
答:我这个是JAVA的,要学习 1.swing图形编程。主要是JFrame,JButton 2.swing事件编程。主要是JButton的ActionListener 3.Integer类,用于String到int的转换。4.语法知识:匿名内部类,接口 5.必要工具:JDK的文档(API)import java.awt.FlowLayout;import java.awt.event.ActionEvent;import java.awt.event...

用java写一个汇率的程序:将人民币与美元、欧元、英镑等多种货币的汇率...
答:程序:import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; class test8{ public static void main(String[] args) { JFrame f=new JFrame(); f.setSize(200, 200); JTextArea t1 = new JTextArea(1,5); JTextArea t2 = new JTextArea(1,5); ...

如何编写一个登录界面的程序,用户名为admin,密码为123456,如果为空提 ...
答:import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class systems extends JFrame implements ActionListener { static systems ss;JPanel panel = new JPanel();JLabel label1 = new JLabel("输入姓名:");JTextField name = new JTextField();JLabel ...

java编程 定义一个接口Person,声明相关的属性和方法,再用Teacher类和Stu...
答:interface Person{public abstract void SetName(String strName);public abstract String GetName();public abstract void SetSex(boolean bSex); //真表示男,假表示女public abstract String GetSex(); //返回“男”或“女”public abstract void ShowInf();}class Student implements Person{priv...

用Java编写一个程序,要求如下:
答:1.内部使用 C 的 longjmp 机制让出一个协程。 因此,如果一个 C 函数 foo 调用了一个 API 函数, 而这个 API 函数让出了(直接或间接调用了让出函数)。 由于 longjmp 会移除 C 栈的栈帧, Lua 就无法返回到 foo 里了。2.为了回避这类问题, 碰到 API 调用中调用让出时,除了那些抛出错误...

用JAVA编程设计一个银行账户类,其中包括以下内容,并用字符界面模拟存款...
答:import java.util.Scanner;public class ZH { private String zh;//账户 private String password;//密码 private String openTime;//开户时间 private String sfz;//身份证号 private double je;//存款金额 public String getZh() { return zh; } public void setZh(String zh) { this.zh ...

用JAVA编写一个程序,要求如下:
答:}public double getEnglish() {return english;}public void setEnglish(double english) {this.english = english;}} --- StudentTest类:(测试类)import java.util.Scanner;public class StudentTest {public static void main(String[] args) {Student student = new Student();Scanner sc = ne...

电脑的编程界面如何进入的
答:1、打开软件后显示的是这个界面,点击‘文件’选择‘新建’。2、选择图中的红线标出的这个标题,还要起一个‘工程名称’可随便起名字,点击确定。3、确定之后,出现这个界面,点击‘完成’。4、这个界面点击‘确定’。5、上几步完成之后,在重新点击‘文件’选择‘新建’出现这个框,选择图中红线标出...

用JAVA编写一个学生类Student的程序
答:package langs;public class Student { private String sno; private String name; private char sex; private int age; public Student() { // TODO Auto-generated constructor stub } public Student(String sno, String name, char sex, int age) { super(); this.sno = sno; this....

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网