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

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

我下面写了一个,初始账号和密码是 nihao  5201314 你可以改或设置

import javaawt;

import javaawtevent;

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("姓名");

lNamesetBounds(50, 70, 60, 30);add(lName);

lPassword=new Label("密码");

lPasswordsetBounds(50, 120, 60, 30);add(lPassword);

tName=new TextField("");

tNamesetBounds(110, 70, 200, 30);add(tName);

tPassword=new TextField("");

tPasswordsetBounds(110, 120, 200, 30);add(tPassword);

login=new Button("登录");

loginsetBounds(90, 200, 60, 30);add(login);

rest=new Button("重输");

restsetBounds(170, 200, 60, 30);add(rest);

exitout=new Button("退出");

exitoutsetBounds(250,200,60,30);add(exitout);

login_clew=new Label("");

loginaddActionListener(this);

restaddActionListener(this);

exitoutaddActionListener(this);

}

public void actionPerformed(ActionEvent e){

if(egetSource()==login){

if(count<2){

if(tNamegetText()equalsIgnoreCase(myName)&&tPasswordgetText()equalsIgnoreCase(myPassword)){

removeAll();

add(login_clew);

add(exitout);

exitoutsetLabel("确定");

login_clewsetBounds(160,120,200,30);

login_clewsetText("欢迎XX用户!");

exitoutsetBounds(170,220,60,30);

}else{

add(login_clew);

login_clewsetBounds(90,160,200,30);

login_clewsetText("请输入正确的信息!");

count++;

}

}else{

add(login_clew);

login_clewsetBounds(90,160,200,30);

login_clewsetText("你输入的次数达到了3次,不能登录了!");

}

}else if(egetSource()==exitout){

Systemexit(1);

}else{

lNamesetText("");

lPasswordsetText("");

}

}

}

public class UserLogin {

public static void main(String args[]){

MyDow m=new MyDow("登录窗口");

minit();

}

}

以下是代码的完整实现,可以在控制台输出 "Hello world":

interface Inter { void show();

}class Outer { public static Inter method() { return new Inter() { public void show() {

Systemoutprintln("Hello world");

}

};

}

}class Inner { public static class InnerDemo { public static void main(String[] args) {

Outermethod()show();

}

}

}

这个程序中定义了一个接口 Inter 和一个外部类 Outer。Outer 类中有一个静态方法 method,该方法返回了一个实现了 Inter 接口的匿名内部类的实例,实现了接口中的 show() 方法。

在 InnerDemo 类的 main 方法中调用 Outermethod() 方法并且调用返回实例的 show() 方法,因此将会在控制台上打印出 "Hello world"。

public class Animal {

public String name;

public int age;

public String gender;

public String color;

public Animal(int age) {

thisage = age;

}

public void happy() {}

public void unhappy(){}

}

public class Dog extends Animal {

public Dog(int age) {

spuer(age);

}

private void actAsDoorkeeper() {}

private void eatBone() {}

}

public class Cat extends Animal {

public Cat(int age) {

super(age);

}

private void catchMouse() {}

private void eatFish() {}

}

public class MainClass{

public static void main(String args[]) {

Dog dog = new Dog(3);

Cat cat = new Cat(4);

if(dogage>catage) {

doghappy();

catunhappy();

}else if(dogage<catage) {

dogunhappy();

cathappy();

}else {

doghappy();

cathappy();

}

}

}

//不知是否是楼主想要的

以上就是关于如何用JAVA编程编写一个界面程序(急求!!!)全部的内容,包括:如何用JAVA编程编写一个界面程序(急求!!!)、JAVA编写程序、java编写程序 速求答案 急!急!急!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10101538.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存