import javax.swing.*;//新的窗口组件包
我们提供的服务有:成都网站设计、做网站、微信公众号开发、网站优化、网站认证、涞水ssl等。为数千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的涞水网站制作公司
import java.awt.*;
import java.awt.event.*;
public class Jisuanqi implements ActionListener
{ JFrame jf=new JFrame();
boolean dotExist, operated, equaled; // 帮助运算的布尔变量
double result; // 目前的结果
char lastOperator; // 表示上一运算符
JTextField jtf; // 显示栏
JButton dot, plus, minus, multi, div, sqrt, equal, change, clear,quyu; // 运算符
JButton[] numbers;
Panel p=new Panel();
// 构造者
public Jisuanqi()
{
jf.setTitle("陈巳伟牌计算器");
// 初始化变量
dotExist = false; // 表示当前的数是否有小数点
operated = false; // 表示任意运算符是否被按下
equaled = false; // 表示等号是否被按下
result = 0;
lastOperator = '?';
// 初始化窗口变量
jtf = new JTextField("0");
jtf.setEditable(false); //设置文本框的可编辑性
jf.setSize(250,200);
jf.setVisible(true);
numbers = new JButton[10];
for (int i = 0; i 10; i++)
numbers[i] = new JButton("" + i);
dot = new JButton(".");
plus = new JButton("+");
minus = new JButton("-");
multi = new JButton("*");
div = new JButton("/");
sqrt = new JButton("√");
equal = new JButton("=");
change= new JButton("±");
clear = new JButton("NC");
quyu=new JButton("%");
p.setLayout(new GridLayout(5,4));
p.add(numbers[1]);
p.add(numbers[2]);
p.add(numbers[3]);
p.add(plus);
p.add(numbers[4]);
p.add(numbers[5]);
p.add(numbers[6]);
p.add(minus);
p.add(numbers[7]);
p.add(numbers[8]);
p.add(numbers[9]);
p.add(multi);
p.add(dot);
p.add(numbers[0]);
p.add(sqrt);
p.add(div);
p.add(equal);
p.add(change);
p.add(clear);
p.add(quyu);
jf.add(jtf,BorderLayout.NORTH);
jf.add(p,BorderLayout.CENTER);
numbers[0].addActionListener(this);
numbers[1].addActionListener(this);
numbers[2].addActionListener(this);
numbers[3].addActionListener(this);
plus.addActionListener(this);
numbers[4].addActionListener(this);
numbers[5].addActionListener(this);
numbers[6].addActionListener(this);
minus.addActionListener(this);
numbers[7].addActionListener(this);
numbers[8].addActionListener(this);
numbers[9].addActionListener(this);
multi.addActionListener(this);
dot.addActionListener(this);
sqrt.addActionListener(this);
div.addActionListener(this);
equal.addActionListener(this);
change.addActionListener(this);
clear.addActionListener(this);
quyu.addActionListener(this);
}
// 对按钮进行反应的方法
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton)e.getSource();
if (btn == clear)
{
jtf.setText("0");
dotExist = false;
operated = false;
equaled = false;
result = 0;
lastOperator = '?';
}
else if (btn == equal)
{
operate('=');
equaled = true;
}
else if (btn == plus)
{
operate('+');
equaled = false;
}
else if (btn == minus)
{
operate('-');
equaled = false;
}
else if (btn == multi)
{
operate('*');
equaled = false;
}
else if (btn == div)
{
operate('/');
equaled = false;
}
else if (btn==quyu){
operate('%');
equaled=false;
}
else if (btn == change)
{
operate('p');
operate('=');
equaled = true;
}
else if (btn == sqrt)
{
operate('s');
operate('=');
equaled = true;
}
else
{
if (equaled)
result = 0;
for (int i = 0; i 10; i++)
if (btn == numbers[i])
{
if (jtf.getText().equals("0"))
jtf.setText("" + i);
else if(! operated)
jtf.setText(jtf.getText() + i);
else
{
jtf.setText("" + i);
operated = false;
}
}
if (btn == dot ! dotExist)
{
jtf.setText(jtf.getText() + ".");
}
}
}
// 进行运算的方法
private void operate(char operator)
{
double currentNumber = Double.valueOf(jtf.getText()).doubleValue();
if (lastOperator == '?')
result = currentNumber;
else if (lastOperator == '+')
result += currentNumber;
else if (lastOperator == '-')
result -= currentNumber;
else if (lastOperator == '*')
result *= currentNumber;
else if (lastOperator == '/')
result /= currentNumber;
else if(lastOperator=='%')
result %=currentNumber;
else if (lastOperator == 'p')
result *= -1;
else if (lastOperator == 's')
result = Math.sqrt(currentNumber);
else if (lastOperator == '=' equaled)
result = currentNumber;
jtf.setText("" + result);
operated = true;
lastOperator = operator;
}
public static void main(String[] args)
{new Jisuanqi();br br }
}
//都是从新手过来的,以下代码供参考
//1.
public class BankAccount {
private static String acctnum;
private static double money;
private static void showAcct() {
System.out.println("账号为: " + acctnum);
}
private static void showMoney() {
System.out.println("余额为: " + money);
}
public BankAccount(String acc, double m) {
this.acctnum = acc;
this.money = m;
}
public static void main(String[] args) {
BankAccount ba = new BankAccount("626600018888", 5000.00);
ba.showAcct();
ba.showMoney();
}
}
//2.
public class Triangle {
private static float a;
private static float b;
private static float c;
public Triangle(float a, float b, float c) {
this.a = a;
this.b = b;
this.c = c;
}
public static boolean judgeTriangle(float a, float b, float c) {
if ((a Math.abs(b - c) a b + c)
(b Math.abs(a - c) b a + c)
(c Math.abs(a - b) c a + b))
return true;
else
return false;
}
public float getCircumference() {
return this.a + this.b + this.c;
}
}
//3.
public class TestTriangle {
public static void main(String[] args) {
Triangle t = new Triangle(5.3f,7.8f,9.3f);
if(t.judgeTriangle(5.3f,7.8f,9.3f)){
System.out.print("能够成三角形,周长为: ");
System.out.printf("%9.2f",t.getCircumference());}
else
System.out.println("不能构成三角形");
}
}
你说的java源代码是指编译成的class文件前的java文件。
当我们运行.java文件时,它会被系统编译成.class文件,例如Test.java编译之后就是Test.class,
源文件就是指Test.java文件,
一般部署项目时,有.class文件就可以发布运行了,但是如果想修改这个系统,.class是不能修改的,要有.java文件才能修改
也可以上网去下反编译软件,就是能把.class文件大部分还原成.java文件的工具,但不是100%还原,而且如果不是正版的,小心有毒啊,什么的。
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class game21 extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();
public static void main(String[] args) {
new game21();
}
public game21() {
super("21点?!");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(170, 350, 106, 28);
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, 26));
label.setText("背面");
label.setBounds(158, 81, 137, 153);
getContentPane().add(label);
label_1.setText("你已经拥有的牌:");
label_1.setBounds(109, 22, 270, 45);
getContentPane().add(label_1);
this.setBounds(200, 300, 501, 528);
this.setVisible(true);
getContentPane().add(getLabel_2());
}
public int randNumber() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 10 + 1);
}
public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合计:" + sum;
label_2.setText(temp);
isWin();
}
public void isWin() {
if (sum 21) {
JOptionPane.showMessageDialog(this, "你输了");
clear();
return;
} else if (sum == 21) {
JOptionPane.showMessageDialog(this, "你赢了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否继续?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}
private void clear() {
label_2.setText("合计:");
sum = 0;
number = 0;
label_1.setText("你已经拥有的牌:");
}
/**
* @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合计:");
label_2.setBounds(313, 35, 66, 18);
}
return label_2;
}
}
真好无聊中。。
当前题目:java课程源代码 java源码书籍推荐
分享路径:https://www.cdcxhl.com/article16/doejsgg.html
成都网站建设公司_创新互联,为您提供全网营销推广、网站排名、关键词优化、品牌网站制作、网站改版、品牌网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联