java小程序代码下载 java小程序开发教程-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

java小程序代码下载 java小程序开发教程

求一java小程序,,像计算器,小游戏,或者什么的。

public class Test {

创新互联主要从事网站建设、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务海陵,10余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

double result = 0;

boolean start = true;

String lastCommand = "+";// 最终的符号

Font font = new Font(null, Font.PLAIN, 25);

Font font2 = new Font(null, Font.PLAIN, 20);

JFrame frame = new JFrame("简易计算器");

JPanel panel1 = new JPanel();

JPanel panel2 = new JPanel();

JPanel panel3 = new JPanel();

JPanel panel4 = new JPanel();

JPanel panel5 = new JPanel();

JTextField text = new JTextField("");

JButton b0 = new JButton("0");

JButton b1 = new JButton("1");

JButton b2 = new JButton("2");

JButton b3 = new JButton("3");

JButton b4 = new JButton("4");

JButton b5 = new JButton("5");

JButton b6 = new JButton("6");

JButton b7 = new JButton("7");

JButton b8 = new JButton("8");

JButton b9 = new JButton("9");

JButton a1 = new JButton("+");

JButton a2 = new JButton("-");

JButton a3 = new JButton("*");

JButton a4 = new JButton("/");

JButton a5 = new JButton("=");

JButton a6 = new JButton(".");

JButton a7 = new JButton("清零");

JButton a8 = new JButton("取消");

JButton a9 = new JButton("sqrt");

JButton a10 = new JButton("+/-");

public void set() {

frame.setSize(400, 350);

frame.setLayout(new GridLayout(5, 1, 2, 2));

panel1.setBackground(Color.black);

panel2.setBackground(Color.red);

panel3.setBackground(Color.blue);

panel4.setBackground(Color.green);

panel5.setBackground(Color.yellow);

panel1.setLayout(new BorderLayout());

panel1.add(text, "Center");

panel2.setLayout(new GridLayout(1, 5, 1, 1));

panel3.setLayout(new GridLayout(1, 5, 1, 1));

panel4.setLayout(new GridLayout(1, 5, 1, 1));

panel5.setLayout(new GridLayout(1, 5, 1, 1));

text.setHorizontalAlignment(JTextField.RIGHT);

b0.setFont(font);

b1.setFont(font);

b2.setFont(font);

b3.setFont(font);

b4.setFont(font);

b5.setFont(font);

b6.setFont(font);

b7.setFont(font);

b8.setFont(font);

b9.setFont(font);

a1.setFont(font);

a2.setFont(font);

a3.setFont(font);

a4.setFont(font);

a5.setFont(font);

a6.setFont(font);

a7.setFont(font2);

a8.setFont(font2);

a9.setFont(font);

a10.setFont(font);

frame.setVisible(true);

}

public void addComponent() {

panel2.add(b7);

panel2.add(b8);

panel2.add(b9);

panel2.add(a4);

panel2.add(a7);

panel3.add(b4);

panel3.add(b5);

panel3.add(b6);

panel3.add(a3);

panel3.add(a8);

panel4.add(b1);

panel4.add(b2);

panel4.add(b3);

panel4.add(a2);

panel4.add(a9);

panel5.add(b0);

panel5.add(a10);

panel5.add(a6);

panel5.add(a1);

panel5.add(a5);

frame.add(panel1);

frame.add(panel2);

frame.add(panel3);

frame.add(panel4);

frame.add(panel5);

}

public void addListener() {

b0.addActionListener(new InsertAction());

b1.addActionListener(new InsertAction());

b2.addActionListener(new InsertAction());

b3.addActionListener(new InsertAction());

b4.addActionListener(new InsertAction());

b5.addActionListener(new InsertAction());

b6.addActionListener(new InsertAction());

b7.addActionListener(new InsertAction());

b8.addActionListener(new InsertAction());

b9.addActionListener(new InsertAction());

a1.addActionListener(new CommandAction());

a2.addActionListener(new CommandAction());

a3.addActionListener(new CommandAction());

a4.addActionListener(new CommandAction());

a5.addActionListener(new CommandAction());

a6.addActionListener(new InsertAction());

a7.addActionListener(new InsertAction());

a8.addActionListener(new InsertAction());

a9.addActionListener(new CommandAction());

a10.addActionListener(new InsertAction());

}

public void go() {

this.set();

this.addComponent();

this.addListener();

}

class InsertAction implements ActionListener {

public void actionPerformed(ActionEvent event1) {

String input = event1.getActionCommand();

if (start) {

text.setText("");

start = false;

if (input.equals("+/-"))

text.setText(text.getText() + "-");

}

if (!input.equals("+/-")) {

if (input.equals("取消")) {

String str = text.getText();

if (str.length() 0)

text.setText(str.substring(0, str.length() - 1));

} else if (input.equals("清零")) {

text.setText("0");

lastCommand = "+";

start = true;

result = 0;

} else

text.setText(text.getText() + input);

}

}

}

class CommandAction implements ActionListener {

public void actionPerformed(ActionEvent event2) {

String command = event2.getActionCommand();

if (start) {

lastCommand = command;

} else { // Double data=new Double(text.getText());

calculator(Double.parseDouble(text.getText()));

lastCommand = command;

start = true;

}

}

}

public void calculator(double x) {

if (lastCommand.equals("+"))

result += x;

else if (lastCommand.equals("-"))

result -= x;

else if (lastCommand.equals("*"))

result *= x;

else if (lastCommand.equals("/"))

result /= x;

else if (lastCommand.equals("="))

result = x;

else if (lastCommand.equals("sqrt"))

result = Math.sqrt(x);

text.setText("" + result);

}

public static void main(String[] args) {

Test a = new Test();

a.go();

}

}

初学者java小程序,求java大神帮我补充一下空缺代码!

import java.util.Arrays;

public class Array2 {

public static void main(String[] args) {

//声明一个名为myArray的数组,该数组有2行,每行列数不等,并为其分配内存空间

int[][] myArray = new int[2][];

myArray[0] = new int[5]; //第一行有5个元素,并为其分配内存空间

myArray[1] = new int[10]; //第二行有10个元素,并为其分配内存空间

for (int j = 0; j myArray[0].length; j++)

//用1-10之间的随机整数给第一行元素赋值

myArray[0][j] = (int)(Math.random() * 10);

//用100-200之间的随机整数给第二行元素赋值

for (int j=0; j myArray[1].length; j++)

myArray[1][j]=(int)(Math.random() * 100 + 100);

for (int i=0; i myArray.length; i++){ //输出myArray数组各元素的值

for (int j=0; j myArray[i].length; j++){

System.out.print(myArray[i][j]+" ");

}

System.out.println();

}

Arrays.sort(myArray[0]); //对第一行元素排序

Arrays.sort(myArray[1]); //对第二行元素排序

System.out.println("\n排序后的数组元素: ");

for (int i=0; imyArray.length;i++){ //再次输出myArray数组各元素的值

for (int j=0; jmyArray[i].length;j++){

System.out.print(myArray[i][j]+" ");

}

System.out.println();

}

}

}

7 3 9 6 7

103 165 166 148 103 179 128 109 120 156

排序后的数组元素:

3 6 7 7 9

103 103 109 120 128 148 156 165 166 179

java编写一个记事本小程序,接着下面的代码写,求大神解救!实现新建,保存,打开功能就行!

package tuxingjiemian;

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

import java.io.File;

import java.io.PrintStream;

public class jishiben extends JFrame {

JPanel jp=new JPanel();

JFrame find_replace=new JFrame();

JMenu file=new JMenu("文件");

JMenu edit=new JMenu("编辑");

JMenu help=new JMenu("帮助");

JMenuBar menubar=new JMenuBar();

JTextArea aa=new JTextArea();

class Open implements ActionListener {

public void actionPerformed(ActionEvent e) {

JFileChooser jf= new JFileChooser();

jf.showOpenDialog(jishiben.this);

try {

PrintStream p=new PrintStream(jf.getSelectedFile().getPath());

} catch (Exception e2) {

}

}

}

class Save implements ActionListener {

public void actionPerformed(ActionEvent e) {

JFileChooser jf= new JFileChooser();

jf.showSaveDialog(jishiben.this);

try {

PrintStream p=new PrintStream(jf.getSelectedFile().getPath());

} catch (Exception e2) {

}

}

}

public jishiben(){

this.setTitle("记事本");

this.setSize(500, 500);

this.setLayout(new BorderLayout());

JMenuItem open=new JMenuItem("打开");

open.addActionListener(new Open());

JMenuItem save=new JMenuItem("保存");

save.addActionListener(new Save());

JMenuItem exit=new JMenuItem("退出");

exit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.exit(0);

}

});

file.add(open);

file.add(save);

file.addSeparator();

file.add(exit);

menubar.add(file);

this.add(new JScrollPane(aa),BorderLayout.CENTER);

JMenuItem copy=new JMenuItem("复制");

JMenuItem past=new JMenuItem("粘贴");

JMenuItem delete=new JMenuItem("删除");

JMenuItem find=new JMenuItem("查找");

JMenuItem replace=new JMenuItem("替换");

copy.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishiben.this.aa.copy();

}

});

past.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishiben.this.aa.paste();

}

});

delete.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

jishiben.this.aa.replaceSelection(null);

}

});

edit.add(copy);

edit.add(past);

edit.add(delete);

edit.add(find);

edit.add(replace);

menubar.add(edit);

help.add(new JMenuItem("帮助"));

menubar.add(help);

this.add(menubar,BorderLayout.NORTH);

this.setVisible(true);

this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new jishiben();

}

};

JAVA小程序编写

1.JavaPow.java

import java.util.Scanner;

public class JavaPow {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("请输入一个数求平方:");

double num = sc.nextDouble();

System.out.println(num + "的平方结果是:" + Math.pow(num, 2));

}

}

2.CompareTest.java

public class CompareTest {

public static void main(String[] args) {

int a = 10, b = 8;

if(ab){

System.out.println("排序结果是:"+b+"\t"+a);

}else{

System.out.println("排序结果是:"+a+"\t"+b);

}

}

}

3.RateMoney.java

import java.util.Scanner;

public class RateMoney {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

double money=0;

double rate=0;

System.out.print("请输入汇款金额:");

money=sc.nextDouble();

if(money0){

rate=0;

}

else if(money0money=100){

rate=1;

}else if(money100money=5000){

rate=money/100;

}else{

rate=50;

}

System.out.println("汇"+money+"元钱需汇款费:"+rate+"元");

}

}

三个都已经写出来了..

你好好看看吧!!

祝你早日成功!


分享文章:java小程序代码下载 java小程序开发教程
标题来源:http://kswsj.cn/article/doccjic.html

其他资讯