重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java有趣实例代码,Java代码示例

求一个JAVA∶猫狗案例代码

代码如下

专注于为中小企业提供网站制作、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业张北免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了超过千家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

abstract class Dongwu {

void chi(){

System.out.println("吃");

}

}

interface Tiao{

void tiao();

}

interface Suan{

void suan();

}

class Mao extends Dongwu implements Tiao{

public void tiao() {

System.out.println("猫会跳高");

}

}

class Gou extends Dongwu implements Suan{

public void suan() {

System.out.println("狗会算数");

}

}

如果有帮助到你,请点击采纳

用java编写一个简单例子,题目如下

package test;

public class Student {

private String name;

private String id;

private String clazz;

private int age;

private String address;

/**

* sayHello方法

*/

public void sayHello() {

System.out.println("学号为" + this.id + "的同学的具体信息如下:");

System.out.println("姓名:" + this.name);

System.out.println("班级:" + this.clazz);

System.out.println("年龄:" + this.age);

System.out.println("家庭住址:" + this.address);

}

/**

* 测试方法

*

* @param args

*/

public static void main(String[] args) {

// 第一问

Student student = new Student();

student.setAddress("百度知道");

student.setAge(1);

student.setClazz("一班");

student.setId("071251000");

student.setName("lsy605604013");

student.sayHello();

// 第二问

Student studentNew = new Student();

studentNew.setAddress("搜搜知道");

studentNew.setAge(2);

studentNew.setClazz("二班");

studentNew.setId("071251001");

studentNew.setName("lady");

if (student.getAge() studentNew.getAge())

studentNew.sayHello();

else if (student.getAge() studentNew.getAge())

student.sayHello();

else

System.out.println("两人一样大");

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getClazz() {

return clazz;

}

public void setClazz(String clazz) {

this.clazz = clazz;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

}

求个JAVA实例代码是关于弹出下拉菜单的

import javax.swing.*;

public class MenuTest extends JFrame{

JMenuBar menuBar;

JMenu menu1,menu2;

JMenuItem jmi1,jmi2,jmi3;

MenuTest(){

setTitle("菜单测试");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setSize(400,300);

menuBar=new JMenuBar();

setJMenuBar(menuBar);

menu1=new JMenu("文件");

menu2=new JMenu("工具");

menuBar.add(menu1);

menuBar.add(menu2);

jmi1=new JMenuItem("打开");

jmi2=new JMenuItem("保存");

jmi3=new JMenuItem("关闭");

menu1.add(jmi1);

menu1.add(jmi2);

menu1.add(jmi3);

setVisible(true);

}

public static void main(String[] args) {

new MenuTest();

}

}

一个简单的例子,没添加动作

请问谁有java编程实例,简单就好

import java.awt.*;

import java.awt.event.*;

public class MyFrame

{

private Frame f;

private String name[]={"1","2","3","4","5","6","7"} ;

private Button Button[]= new Button[name.length];

private TextField tf;

private Panel p;

private int count = 0;

public void setup()

{

f = new Frame("计算器");

tf = new TextField(40);

p = new Panel();

p.setLayout(new GridLayout(4,6,5,5));

for(int i=0;iname.length;i++)

{

Button[i]= new Button(name[i]);

p.add(Button[i]);

}

f.add(tf,BorderLayout.NORTH);

f.add(p,BorderLayout.SOUTH);

f.addWindowListener(new MyWindowListener());

f.pack();

f.setResizable(false);//锁定大小 或者定义一个ScrollPane对象 将panel先装入Scrollpane再将Scroll装入Frame

f.show();

}

public static void main(String[] args)

{

MyFrame mf = new MyFrame();

mf.setup();

}

class MyWindowListener extends WindowAdapter

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

}


网页名称:java有趣实例代码,Java代码示例
网页链接:http://cqcxhl.com/article/phjsde.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP