大橙子网站建设,新征程启航

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

大神运用java写代码 java写代码的思路

求大神用Java编写出这个程序,要有具体代码,万分感激,定采纳

按照你的要求编写的JavaGUI程序如下:

创新互联公司主要从事成都网站制作、成都网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务平桥,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;

public class HH extends JFrame implements ActionListener{

JPanel jp1=new JPanel();

JPanel jp2=new JPanel();

JPanel jp3=new JPanel();

JTextField jtf=new JTextField(20);

JButton jb1=new JButton("显示");

JButton jb2=new JButton("清除");

HH(){

jb1.addActionListener(this);

jb2.addActionListener(this);

jp1.setLayout(new GridLayout(2,1));

jp3.add(jtf);

jp2.add(jb1);jp2.add(jb2);

jp1.add(jp3);jp1.add(jp2);

getContentPane().add(jp1);

setSize(300, 120);

setLocationRelativeTo(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setVisible(true);

}

@Override

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jb1){

jtf.setText("java程序设计");

}

if(e.getSource()==jb2){

jtf.setText("");

}

}

public static void main(String[] args) {

new HH();

}

}

急,求大神帮我用JAvA写下下面这两道题的代码!!!!!!!!!!!

1)for:

import javax.swing.*;

public class moren {

public static void main(String agrs[]){

int i=0,n=0,s=1;

n=Integer.parseInt(JOptionPane.showInputDialog("输入N的值:"));

if (0 == n)

s=1;

else

for (i=1;i=n;i++)

s*=i;

JOptionPane.showMessageDialog(null,+n+" 的阶乘为:"+s,"阶乘计算器",JOptionPane.PLAIN_MESSAGE);

}

}

2)while:

import javax.swing.*;

public class moren {

public static void main(String agrs[]){

int i=1,n=0,s=1;

n=Integer.parseInt(JOptionPane.showInputDialog("输入N的值:"));

if (0 == n)

s=1;

else

while(i=n)

{

s*=i;

i++;

}

JOptionPane.showMessageDialog(null,+n+" 的阶乘为:"+s,"阶乘计算器",JOptionPane.PLAIN_MESSAGE);

}

}

3)do-while:

import javax.swing.*;

public class moren {

public static void main(String agrs[]){

int i=1,n=0,s=1;

n=Integer.parseInt(JOptionPane.showInputDialog("输入N的值:"));

if (0 == n)

s=1;

else

do{

s*=i;

i++;

}while(i=n);

JOptionPane.showMessageDialog(null,+n+" 的阶乘为:"+s,"阶乘计算器",JOptionPane.PLAIN_MESSAGE);

}

}

2、import javax.swing.*;

public interface Area{    //定义接口

 public abstract double getArea();

}

class Ellipse implements Area{   //定义类

 double r1,r2; // 定义两个半径

public Ellipse(double a, double b){   //构造方法

r1=a; r2=b;

}

public  double getArea(){

double mj=Math.PI*r1*r2;

return mj;

}

public static void main(String[] args) {

double r1=0,r2=0;

r1=Float.parseFloat(JOptionPane.showInputDialog("输入长半径a:"));

r2=Float.parseFloat(JOptionPane.showInputDialog("输入短半径b:"));

Ellipse e1=new Ellipse(r1,r2);

JOptionPane.showMessageDialog(null,"此椭圆的面积为:"+e1.getArea(),"椭圆面积计算器",JOptionPane.PLAIN_MESSAGE);

}

}

求助大神如何用Java写出这两个题目的代码?

第一题

package baidu;

public class Student {

protected String name;

protected int age;

public Student(String name, int age) {

this.name = name;

this.age = age;

}

public void show(){

System.out.println("name = " + name);

System.out.println("age = " + age);

}

}

---------------------------------

package baidu;

public class Undergraduate extends Student {

private String degree;

public Undergraduate(String name, int age, String degree) {

super(name, age);

this.degree = degree;

}

public void show(){

System.out.println("name = " + name);

System.out.println("age = " + age);

System.out.println("degree = " + degree);

}

}

------------------------

package baidu;

public class TestRun {

public static void main(String[] args) {

Student s = new Student("singi",12);

s.show();

Undergraduate ug = new Undergraduate("lily",23,"本科");

ug.show();

}

}

输出:

name = singi

age = 12

name = lily

age = 23

degree = 本科

第二题:

package baidu;

public class Man {

String name;

public Man(String name) {

this.name = name;

}

public void business(){

System.out.println("在方法内输出谈生意");

}

}

----------------

package baidu;

public class SuperMan extends Man {

String name;

public SuperMan(String name, String name1) {

super(name);

this.name = name1;

}

@Override

public void business() {

System.out.println("在方法内输出谈几个亿的大单子");

}

public void fly(){

System.out.println("在方法内输出超人不会飞");

}

}

------------------

package baidu;

public class TestMan {

public static void main(String[] args) {

Man m = new Man("singi");

System.out.println(m.name);

m.business();

SuperMan sm = new SuperMan("lily","xiaoming");

System.out.println(sm.name);

sm.business();

sm.fly();

}

}

输出:

singi

在方法内输出谈生意

xiaoming

在方法内输出谈几个亿的大单子

在方法内输出超人不会飞


文章题目:大神运用java写代码 java写代码的思路
本文来源:http://dzwzjz.com/article/ddgssig.html
在线咨询
服务热线
服务热线:028-86922220
TOP