代碼如下
專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)張北免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了超過千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
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("狗會算數(shù)");
}
}
如果有幫助到你,請點擊采納
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("學(xué)號為" + this.id + "的同學(xué)的具體信息如下:");
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;
}
}
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("關(guān)閉");
menu1.add(jmi1);
menu1.add(jmi2);
menu1.add(jmi3);
setVisible(true);
}
public static void main(String[] args) {
new MenuTest();
}
}
一個簡單的例子,沒添加動作
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);
}
}
}