代碼如下
專注于為中小企業(yè)提供網(wǎng)站制作、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)張北免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了超過(guò)千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(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("貓會(huì)跳高");
}
}
class Gou extends Dongwu implements Suan{
public void suan() {
System.out.println("狗會(huì)算數(shù)");
}
}
如果有幫助到你,請(qǐng)點(diǎn)擊采納
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é)號(hào)為" + this.id + "的同學(xué)的具體信息如下:");
System.out.println("姓名:" + this.name);
System.out.println("班級(jí):" + this.clazz);
System.out.println("年齡:" + this.age);
System.out.println("家庭住址:" + this.address);
}
/**
* 測(cè)試方法
*
* @param args
*/
public static void main(String[] args) {
// 第一問(wèn)
Student student = new Student();
student.setAddress("百度知道");
student.setAge(1);
student.setClazz("一班");
student.setId("071251000");
student.setName("lsy605604013");
student.sayHello();
// 第二問(wèn)
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("菜單測(cè)試");
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("打開(kāi)");
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();
}
}
一個(gè)簡(jiǎn)單的例子,沒(méi)添加動(dòng)作
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("計(jì)算器");
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);//鎖定大小 或者定義一個(gè)ScrollPane對(duì)象 將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有趣實(shí)例代碼,Java代碼示例
文章地址:http://m.rwnh.cn/article14/phjsde.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站改版、品牌網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)