class Ball {
public void play() {
Systemoutprintln("玩球儿");
}
}
class Football extends Ball {
public void play() {
Systemoutprintln("使用足球运动");
}
}
class Basketball extends Ball {
public void play() {
Systemoutprintln("使用篮球运动");
}
}
public class TestMain {
public static void main(String[] args) {
TestMain tm = new TestMain();
tmtestPlay();
}
public void testPlay() {
Ball ball = new Football();
ballplay();
ball = new Basketball();
ballplay();
}
}
/
D:\>javac TestMainjava
D:\>java TestMain
使用足球运动
使用篮球运动
/
package com;
public interface PlaneGraphics {
public abstract double area();
public abstract double perimeter();
public abstract void print();
}
package com;
public class Rectangle implements PlaneGraphics{
private double x = 75;
private double y = 157;
private double s = 0;
private double l= 0;
public double area() {
s = x y;
return s;
}
public double perimeter() {
l = 2 (x + y);
return l;
}
public void print() {
Systemoutprintln("这是长方形");
Systemoutprintln("长方形的宽度:"+x+"长方形的长度:"+y);
Systemoutprintln("长方形的面积:"+s);
Systemoutprintln("长方形的周长:"+l);
}
package com;
public class Ellipse implements PlaneGraphics {
private double a = 57;
private double b = 25;
private double s = 0;
private double l = 0;
private double pie = 314;
public double area() {
s = pie a b;
return s;
}
public double perimeter() {
double m = 0;
m = javalangMathsqrt(a b);
l = pie (15 (a+b) - m);
return l;
}
public void print() {
Systemoutprintln("这是椭圆形");
Systemoutprintln("椭圆形的a轴长:"+a+"椭圆形的b轴长:"+b);
Systemoutprintln("椭圆形的面积:"+s);
Systemoutprintln("椭圆形的周长:"+l);
}
}
package com;
public class Test {
public static void main(String[] args) {
Rectangle rec = new Rectangle();
recarea();
recperimeter();
recprint();
Ellipse ell = new Ellipse();
ellarea();
ellperimeter();
ellprint();
}
}
public test_03(){
init();
}
public void init(){
JLabel jl_1=new JLabel("用户名");
JLabel jl_2=new JLabel("密码");
JTextField jtf=new JTextField();
JPasswordField jpf=new JPasswordField();
JButton button_1=new JButton("确定");
JPanel panel=new JPanel();
panelsetLayout(null);
jl_1setBounds(30, 50, 50, 30);
jl_2setBounds(30,90,50,30);
jtfsetBounds(100, 50, 100, 30);
jpfsetBounds(100, 90, 100, 30);
button_1setBounds(110, 130, 80, 30);
paneladd(jl_1);
paneladd(jl_2);
paneladd(jtf);
paneladd(jpf);
paneladd(button_1);
thisadd(panel);
thissetSize(300, 250);
thissetLocation(400, 300);
thissetVisible(true);
}
public static void main(String[] args) {
new test_03();
}
以上就是关于java一个简单小程序,求高手帮忙编写,万分感谢全部的内容,包括:java一个简单小程序,求高手帮忙编写,万分感谢、求助,用java编写一个小程序、编写一个java小程序!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)