百度
360搜索
搜狗搜索

java课程设计题目及源代码,求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊~~~详细介绍

本文目录一览: java课程设计题目及代码是什么?

java课程设计题目及代码分别是:
1、题目:计算器。设计内容是设计一个图形界面(GUI)的计算器应用程序,完成简单的算术运算。
设计要求是设计的计算器应用程序可以完成家法、减法、乘法、除法和取余运算。且有小数点、正负号、求倒数、退格和清零功能。
2、代码:
数字按钮NumberButton类如下:
import java.awt.
import java.awt.event.
import javax.swing.
public class NumberButton extends Button.
{
int number.
public NumberButton(int number).
{
super(""+number).
this.number=number.
setForeground(Color.blue).
}
public int getNumber().
{
return number;
}
}
其它java课程设计题目及代码是:
题目:华容道。编写一个按钮的子类,使用该子类创建的对象代表华容道中的人物。通过焦点事件控制人物颜色,当人物获得焦点时颜色为蓝色,当失去焦点时颜色为灰色。
通过键盘事件和鼠标事件来实现曹操、关羽等人物的移动。当人物上发生鼠标事件或键盘事件时,如果鼠标指针的位置是在人物的下方(也就是组件的下半部分)或按下键盘的“↓“键,该人物向下移动。向左、向右和向上的移动原理类似。
代码是:
String name[]={"曹操","关羽","张","刘","马","许","兵","兵","兵","兵"}.
for(int i=0;i
<name.length;i++).
{

person[i]=new Person(i,name[i]).

person[i].addKeyListener(this).

person[i].addMouseListener(this).

// person[i].addFocusListener(new Person).

add(person[i]).

}

person[0].setBounds(104,54,100,100).

person[1].setBounds(104,154,100,50).

person[2].setBounds(54,154,50,100).

person[3].setBounds(204,154,50,100).

person[4].setBounds(54,54,50,100).

person[5].setBounds(204,54,50,100);

person[6].setBounds(54,254,50,50);

person[7].setBounds(204,254,50,50);

person[8].setBounds(104,204,50,50);

person[9].setBounds(154,204,50,50);
</name.length;i++).

java课程设计源代码(急!!!!)

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题目的源代码!!!

看代码:
import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.PrintWriter;public class Demo { // 获得系统换行符 private static final String LINE_SEP = System.getProperty("line.separator"); public static void main(String[] args) throws Exception { try (BufferedReader in = new BufferedReader( new InputStreamReader(System.in))) { String line; StringBuilder sBuilder = new StringBuilder(); while (true) { line = in.readLine(); // 读入一行字符串 if (line == null || "exit".equals(line)) { break; } sBuilder.append(line).append(LINE_SEP); } // 将 sBuilder 中的数据写入 log.txt try (PrintWriter writer = new PrintWriter("log.txt")) { writer.print(sBuilder.toString()); } } }}编译运行:

求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊~~~

。。。大学生,认真吧,出来就知道当初没白学!
我劝你别问,随便一本java书都有,就最垃圾的java书都有,你去图书馆找找吧...
完整的Java程序:
public class Test32 {
public static void main(String[] args) {
Complex c1 = new Complex(2, -1);
Complex c2 = new Complex(3, 4);
int m = 3;
System.out.println(c1.toString() + "的绝对值:" + c1.abs());
System.out.println(c1.toString() + "自增后:" + c1.addBySelf());
System.out.println(c1.toString() + "自减后:" + c1.subtractBySelf());
System.out.println("(" + c1.toString() + ") + (" + c2.toString() + ") = " + c1.add(c2));
System.out.println("(" + c1.toString() + ") - (" + c2.toString() + ") = " + c1.subtract(c2));
System.out.println("(" + c1.toString() + ") * (" + c2.toString() + ") = " + c1.multiply(c2));
System.out.println("(" + c1.toString() + ") / (" + c2.toString() + ") = " + c1.divide(c2));
System.out.println(c1.toString() + "的" + m + "次方 = " + c1.power(m));
}
}
//复数类:初始化复数、求其绝对值、复数的加、减、乘、除、乘方、自加、自减
class Complex{
protected double real; //实部
protected double image; //虚部

public Complex(){
real = image = 0;
}

public Complex(double real, double image){
this.real = real;
this.image = image;
}

//复数的绝对值
public Complex abs(){
return new Complex(Math.abs(this.real), Math.abs(this.image));
}

//复数相加
public Complex add(Complex c){
return new Complex(this.real + c.real, this.image + c.image);
}

//复数相减
public Complex subtract(Complex c){
return new Complex(this.real - c.real, this.image - c.image);
}

//复数相乘
public Complex multiply(Complex c){
return new Complex(this.real * c.real - this.image * c.image,
this.real * c.image + this.image * c.real);
}

//复数相除
public Complex divide(Complex c){
return new Complex((this.real * c.real + this.image * c.image) / (c.real * c.real + c.image * c.image),
(this.image * c.real - this.real * c.image) / (c.real * c.real + c.image * c.image));
}

//复数乘方
public Complex power(int m){
if(m < 0)
return new Complex();
if(m == 0)
return new Complex(1, 0);

Complex c = this;
for(int i=1; i
<m; i++){
c = c.multiply(this);

}

return c;

}

//复数自增

public Complex addBySelf(){

return new Complex(++this.real, ++this.image);

}

//复数自减

public Complex subtractBySelf(){

return new Complex(--this.real, --this.image);

}

public String toString(){

if(this.real == 0)

if(this.image == 0)

return "0";

else

return this.image + "i";

else

if(this.image == 0)

return this.real + "";

else if(this.image > 0)

return this.real + "+" + this.image + "i";

else

return this.real + "" + this.image + "i";

}

}

运行测试:

2.0-1.0i的绝对值:2.0+1.0i

2.0-1.0i自增后:3.0

3.0自减后:2.0-1.0i

(2.0-1.0i) + (3.0+4.0i) = 5.0+3.0i

(2.0-1.0i) - (3.0+4.0i) = -1.0-5.0i

(2.0-1.0i) * (3.0+4.0i) = 10.0+5.0i

(2.0-1.0i) / (3.0+4.0i) = 0.08-0.44i

2.0-1.0i的3次方 = 2.0-11.0i

跪求一个JAVA课程设计, 学生信息管理系统 含全源代码 设计报告

现在谁家也不缺孝子,又跪又求的,瞧这点出息!
-----------
可以通过Baidu Hi告知我们
有机会可能完成你所面临的任务
相关的要求也可能告知我们
ES:\\48500D47152892DD75348C92BEE59E62
交易提醒:预付定金是诈骗
我有JAVA课程设计, 学生信息管理系统
import java.awt.*;
import java.awt.event.*;
public class DengLuJieMian extends Frame implements ActionListener
{
Label username=new Label("用户名:");//使用文本创建一个用户名标签
TextField t1=new TextField();//创建一个文本框对象
Label password=new Label("密码:");//创建一个密码标签
TextField t2=new TextField();
Button b1=new Button("登陆");//创建登陆按钮
Button b2=new Button("取消");//创建取消按钮
public DengLuJieMian()
{
this.setTitle("学生信息管理系统");//设置窗口标题
this.setLayout(null);//设置窗口布局管理器
username.setBounds(50,40,60,20);//设置姓名标签的初始位置
this.add(username);// 将姓名标签组件添加到容器
t1.setBounds(120,40,80,20);// 设置文本框的初始位置
this.add(t1);// 将文本框组件添加到容器
password.setBounds(50,100,60,20);//密码标签的初始位置
this.add(password);//将密码标签组件添加到容器
t2.setBounds(120,100,80,20);//设置密码标签的初始位置
this.add(t2);//将密码标签组件添加到容器
b1.setBounds(50,150,60,20);//设置登陆按钮的初始位置
this.add(b1);//将登陆按钮组件添加到容器
b2.setBounds(120,150,60,20);//设置取消按钮的初始位置
this.add(b2);// 将取消按钮组件添加到容器
b1.addActionListener(this);//给登陆按钮添加监听器
b2.addActionListener(this);// 给取消按钮添加监听器
this.setVisible(true);//设置窗口的可见性
this.setSize(300,200);//设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});//通过内部类重写关闭窗体的方法
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)//处理登陆事件
{
String name=t1.getText();
String pass=t2.getText();
if(name!=null&&pass.equals("000123"))//判断语句
{
new StudentJieMian();
}
}
}
public static void main(String args[])//主函数
{
new DengLuJieMian();
}
}
以下方法实现了学生界面设计
import java.awt.*;
import java.awt.event.*;
class StudentJieMian extends Frame implements ActionListener
{
MenuBar m=new MenuBar();//创建菜单栏
Menu m1=new Menu("信息");//创建菜单“信息”
MenuItem m11=new MenuItem("插入");//创建“插入”的菜单项
MenuItem m12=new MenuItem("查询");
Menu m2=new Menu("成绩");//创建菜单“成绩”
MenuItem m21=new MenuItem("查询");
public StudentJieMian()
{
this.setTitle("学生界面");//设置窗口标题
this.setLayout(new CardLayout());//设置窗口布局管理器
this.setMenuBar(m);//将菜单栏组件添加到容器
m.add(m1);//将信息菜单放入菜单栏
m.add(m2);
m1.add(m11);//将“插入”菜单项添加到“信息”菜单
m1.add(m12); //将“查询”菜单项添加到“信息”菜单
m2.add(m21); //将“查询”菜单项添加到“成绩”菜单
m11.addActionListener(this); //给“插入”菜单项添加监听器
m12.addActionListener(this); //给“查询”菜单项添加监听器
m21.addActionListener(this); //给“查询”菜单项添加监听器
this.setVisible(true); //设置窗口的可见性
this.setSize(300,200); //设置窗口的大小
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);//关闭窗口
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==m11) //处理“添加信息”事件
{
new AddStudent();
}
if(e.getSource()==m12) //处理“查询信息”事件
{
new SelectStudent();
}
if(e.getSource()==m21) //处理“查询成绩”事件
{
new ChengJiStudent();
}
}
public static void main(String args[])
{ new StudentJieMian(); //创建一个对象 }

JAVA课程设计计算器的源代码

比较完整的Java计算器
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class calculator extends JFrame implements ActionListener
{//这里我把JFrame写成Frame,这个错误找了好久
JFrame frame;
private JButton jia=new JButton("+");
private JButton jian=new JButton("-");
private JButton cheng=new JButton("*");
private JButton chu=new JButton("/");
private JButton qiuyi=new JButton("%");
private JButton deng=new JButton("=");
private JButton fu=new JButton("+/-");
private JButton dian=new JButton(".");
private JButton kai=new JButton("sqrt");
private JButton diao=new JButton("1/x");
private JButton aa=new JButton("A");
private JButton bb=new JButton("B");
private JButton cc=new JButton("C");
private JButton dd=new JButton("D");
private JButton ee=new JButton("E");
private JButton ff=new JButton("F");
private TextField k1=new TextField();
private objConversion convert = new objConversion();
JMenuItem copy,paste,s,t,help,about,me;
JRadioButton sixteen,ten,eight,two;
JButton backspace,ce,c,num0,num1,num2,num3,num4,num5,num6,num7,num8,num9;
Container cp;
JTextField text;
String copycontent="";
boolean clickable=true,clear=true;
int all=0;
double qian;
String fuhao;
int jin=10,first=1;

public calculator()
{
setTitle("计算器-杨彩制作");
setSize(400,300);
setLocation(250,200);
text=new JTextField(25);
// text.setEnabled(false);
text.setText("0.");
text.setHorizontalAlignment(JTextField.RIGHT);//从右到左
JPanel cp1=new JPanel();
JPanel cp2=new JPanel();
JPanel cp3=new JPanel();

cp=getContentPane();
cp.add(cp1,"North");
cp.add(cp2,"Center");
cp.add(cp3,"South");

cp1.setLayout(new GridLayout(1,6));
cp2.setLayout(new GridLayout(2,4));
cp3.setLayout(new GridLayout(6,6));

sixteen=new JRadioButton("十六进制");
sixteen.setVisible(false);
ten=new JRadioButton("十进制",true);
ten.setVisible(false);
eight=new JRadioButton("八进制");
eight.setVisible(false);
two=new JRadioButton("二进制");
two.setVisible(false);
sixteen.addActionListener(this);
ten.addActionListener(this);
eight.addActionListener(this);
two.addActionListener(this);
ButtonGroup btg=new ButtonGroup();

btg.add(sixteen);
btg.add(ten);
btg.add(eight);
btg.add(two);

JTextField t3=new JTextField(25);
cp1.add(text);
// text.setEnabled(false);
text.setEditable(false);
text.setBackground(new Color(255, 255, 255));

cp2.add(sixteen);
cp2.add(ten);
cp2.add(eight);
cp2.add(two);

backspace=new JButton("Backspace");
backspace.setForeground(new Color(255,0,0));
backspace.addActionListener(this);
ce=new JButton("CE");
ce.setForeground(new Color(255,0,0));
ce.addActionListener(this);
c=new JButton("C");
c.setForeground(new Color(255,0,0));
c.addActionListener(this);
k1.setVisible(false);
cp2.add(k1);
cp2.add(backspace);
cp2.add(ce);
cp2.add(c);

阅读更多 >>>  java和c++哪个难,java和c哪个简单

num0=new JButton("0");
num1=new JButton("1");
num2=new JButton("2");
num3=new JButton("3");
num4=new JButton("4");
num5=new JButton("5");
num6=new JButton("6");
num7=new JButton("7");
num8=new JButton("8");
num9=new JButton("9");
cp3.add(num7);
num7.addActionListener(this);
cp3.add(num8);
num8.addActionListener(this);
cp3.add(num9);
num9.addActionListener(this);
cp3.add(chu);
chu.setForeground(new Color(255,0,0));
chu.addActionListener(this);
cp3.add(kai);
kai.addActionListener(this);
cp3.add(num4);
num4.addActionListener(this);
cp3.add(num5);
num5.addActionListener(this);
cp3.add(num6);
num6.addActionListener(this);
cp3.add(cheng);
cheng.setForeground(new Color(255,0,0));
cheng.addActionListener(this);
cp3.add(qiuyi);
qiuyi.addActionListener(this);
cp3.add(num1);
num1.addActionListener(this);
cp3.add(num2);
num2.addActionListener(this);
cp3.add(num3);
num3.addActionListener(this);
cp3.add(jian);
jian.setForeground(new Color(255,0,0));
jian.addActionListener(this);
cp3.add(diao);
diao.addActionListener(this);
cp3.add(num0);
num0.addActionListener(this);
cp3.add(fu);
fu.addActionListener(this);
cp3.add(dian);
dian.addActionListener(this);
cp3.add(jia);
jia.setForeground(new Color(255,0,0));
jia.addActionListener(this);
cp3.add(deng);
deng.setForeground(new Color(255,0,0));
deng.addActionListener(this);
cp3.add(aa);
aa.addActionListener(this);
cp3.add(bb);
bb.addActionListener(this);
cp3.add(cc);
cc.addActionListener(this);
cp3.add(dd);
dd.addActionListener(this);
cp3.add(ee);
ee.addActionListener(this);
cp3.add(ff);
ff.addActionListener(this);
aa.setVisible(false);
bb.setVisible(false);
cc.setVisible(false);
dd.setVisible(false);
ee.setVisible(false);
ff.setVisible(false);

JMenuBar mainMenu = new JMenuBar();
setJMenuBar(mainMenu);
JMenu editMenu = new JMenu("编辑");
JMenu viewMenu = new JMenu("查看");
JMenu helpMenu = new JMenu("帮助");
mainMenu.add(editMenu);
mainMenu.add(viewMenu);
mainMenu.add(helpMenu);

copy = new JMenuItem(" 复制");
paste = new JMenuItem(" 粘贴");
KeyStroke copyks=KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK);
copy.setAccelerator(copyks);//设置退出菜单选项加上快捷键
KeyStroke pasteks=KeyStroke.getKeyStroke(KeyEvent.VK_V,Event.CTRL_MASK);
paste.setAccelerator(pasteks);//设置退出菜单选项加上快捷键
editMenu.add(copy);
editMenu.add(paste);
copy.addActionListener(this);
paste.addActionListener(this);

t = new JMenuItem("●标准型");
s = new JMenuItem(" 科学型");
viewMenu.add(t);
viewMenu.add(s);
t.addActionListener(this);
s.addActionListener(this);

help = new JMenuItem(" 帮助主题");
about = new JMenuItem(" 关于计算器");
me = new JMenuItem(" 作者主页");
helpMenu.add(help);
helpMenu.add(about);
helpMenu.add(me);
help.addActionListener(this);
about.addActionListener(this);
me.addActionListener(this);

addWindowListener(new WindowDestroyer());//结束窗口
}

public void actionPerformed(ActionEvent e)
{//响应动作代码

if(first==1)
text.setText("");
first=0;//第一次把文本框0.清空
Object temp = e.getSource();
if(temp==copy)
{
copycontent = text.getText();
}
if(temp==paste)
{
text.setText(text.getText()+copycontent);

}
if(temp==t)
{//标准

sixteen.setVisible(false);
ten.setVisible(false);
eight.setVisible(false);
two.setVisible(false);
t.setText("●标准型");
s.setText(" 科学型");
aa.setVisible(false);
bb.setVisible(false);
cc.setVisible(false);
dd.setVisible(false);
ee.setVisible(false);
ff.setVisible(false);
}
if(temp==s)
{//科学

sixteen.setVisible(true);
ten.setVisible(true);
eight.setVisible(true);
two.setVisible(true);
t.setText(" 标准型");
s.setText("●科学型");
aa.setVisible(true);
bb.setVisible(true);
cc.setVisible(true);
dd.setVisible(true);
ee.setVisible(true);
ff.setVisible(true);
aa.setEnabled(false);
bb.setEnabled(false);
cc.setEnabled(false);
dd.setEnabled(false);
ee.setEnabled(false);
ff.setEnabled(false);

}
if(temp==help)
{ //打开系统帮助文件 要查资料
try
{
String filePath = "C:/WINDOWS/Help/calc.chm";
Runtime.getRuntime().exec("cmd.exe /c "+filePath);

}
catch(Exception eeee)
{
System.out.println("打开系统的计算器出错");
}
}
if(temp==about)
{
JOptionPane.showMessageDialog(frame," Java计算器\n 杨彩 制作\n\n http://blog.sina.com.cn/m/yangcai","关于计算器",JOptionPane.INFORMATION_MESSAGE); ;
}
if(temp==me)
{
try
{
Process p = Runtime.getRuntime().exec("explorer http://blog.sina.com.cn/m/yangcai");
}
catch(Exception eeee)
{
System.out.println("打开指定网页出错");
}
}

try
{
if(temp==sixteen)
{
String hex=text.getText();
int inthex=Integer.parseInt(hex,jin);//先把数变为10进制
text.setText(convert.decHex(inthex)) ;
jin=16;
aa.setEnabled(true);
bb.setEnabled(true);
cc.setEnabled(true);
dd.setEnabled(true);
ee.setEnabled(true);
ff.setEnabled(true);
num2.setEnabled(true);
num3.setEnabled(true);
num4.setEnabled(true);
num5.setEnabled(true);
num6.setEnabled(true);
num7.setEnabled(true);
num8.setEnabled(true);
num9.setEnabled(true);
}
if(temp==eight)
{
String oct =text.getText();
int intoct=Integer.parseInt(oct,jin);
text.setText(convert.decOct(intoct)) ;
jin=8;

aa.setEnabled(false);
bb.setEnabled(false);
cc.setEnabled(false);
dd.setEnabled(false);
ee.setEnabled(false);
ff.setEnabled(false);
num2.setEnabled(true);
num3.setEnabled(true);
num4.setEnabled(true);
num5.setEnabled(true);
num6.setEnabled(true);
num7.setEnabled(true);
num8.setEnabled(false);
num9.setEnabled(false);
}
if(temp==two)
{
String bin=text.getText();
int intbin=Integer.parseInt(bin,jin);
text.setText(convert.decBin(intbin));
jin=2;

aa.setEnabled(false);
bb.setEnabled(false);
cc.setEnabled(false);
dd.setEnabled(false);
ee.setEnabled(false);
ff.setEnabled(false);
num2.setEnabled(false);
num3.setEnabled(false);
num4.setEnabled(false);
num5.setEnabled(false);
num6.setEnabled(false);
num7.setEnabled(false);
num8.setEnabled(false);
num9.setEnabled(false);
}
if(temp==ten)
{
String dec=text.getText();
int intdec=Integer.parseInt(dec,jin);
// text.setText(convert.decDec(intdec)); //本句会把123变成321
text.setText(intdec+"");
jin=10;
aa.setEnabled(false);
bb.setEnabled(false);
cc.setEnabled(false);
dd.setEnabled(false);
ee.setEnabled(false);
ff.setEnabled(false);
num2.setEnabled(true);
num3.setEnabled(true);
num4.setEnabled(true);
num5.setEnabled(true);
num6.setEnabled(true);
num7.setEnabled(true);
num8.setEnabled(true);
num9.setEnabled(true);
}
}
catch(Exception ee)
{
System.out.println("转换出错,可能你没有输入任何字符");
text.setText("转换出错");
clear=false;
}

if(temp==backspace)
{//退格
String s = text.getText();
text.setText("");
for (int i = 0; i < s.length() - 1; i++)
{
char a = s.charAt(i);
text.setText(text.getText() + a);
}
}

if (temp==ce)
{
text.setText("0.");
clear=true;
first=1;
}
if (temp==c)
{
text.setText("0."); ;
clear=true;
first=1;
}

if(temp==num0)
{
if(clear==false)//判断是否点击了符号位
text.setText("");
text.setText(text.getText()+"0");
}

if(temp==num1)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"1");
clear=true;//第二次不在清空(前二句)
}

if(temp==num2)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"2");
clear=true;
}

if(temp==num3)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"3");
clear=true;
}

if(temp==num4)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"4");
clear=true;
}

if(temp==num5)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"5");
clear=true;
}

if(temp==num6)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"6");
clear=true;
}
if(temp==num7)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"7");
clear=true;
}

if(temp==num8)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"8");
clear=true;
}

if(temp==num9)
{
if(clear==false)
text.setText("");
text.setText(text.getText()+"9");
clear=true;
}
if(temp==aa)
{
text.setText(text.getText()+"A");
}
if(temp==bb)
{
text.setText(text.getText()+"B");
}

if(temp==cc)
{
text.setText(text.getText()+"C");
}

if(temp==dd)
{
text.setText(text.getText()+"D");
}

if(temp==ee)
{
text.setText(text.getText()+"E");
}
if(temp==ff)
{
text.setText(text.getText()+"F");
}
if(temp==dian)
{
clickable=true;
for (int i = 0; i < text.getText().length(); i++)
if ('.' == text.getText().charAt(i))
{
clickable=false;
break;
} //第一层判断是否里面含有小数点;

if(clickable==true)//第二坛判断
text.setText(text.getText()+".");

}

try
{
if(temp==jia)
{//加法
qian=Double.parseDouble(text.getText());
fuhao="+";
clear=false;
}
if(temp==jian)
{
qian=Double.parseDouble(text.getText());
fuhao="-";
clear=false;
;

}
if(temp==cheng)
{
qian=Double.parseDouble(text.getText());
fuhao="*";
clear=false;

}
if(temp==chu)
{
qian=Double.parseDouble(text.getText());
fuhao="/";
clear=false;

}
if(temp==deng)
{
double ss=Double.parseDouble(text.getText());
text.setText("");
if(fuhao=="+")
text.setText(qian+ss+"");
if(fuhao=="-")
text.setText(qian-ss+"");
if(fuhao=="*")
text.setText(qian*ss+"");
if(fuhao=="/")
text.setText(qian/ss+"");
clear=false;//要清空前一次的数据
;

}

if(temp==kai)
{
String s = text.getText();
if (s.charAt(0) == '-')
{
text.setText("负数不能开根号");
}
else
text.setText(Double.toString(java.lang.Math.sqrt(Double.parseDouble(text.getText()))));
clear=false;
}

if(temp==diao)
{

if (text.getText().charAt(0) == '0'&&text.getText().length() == 1)
{
text.setText("除数不能为零");
}
else
{
boolean isDec = true;
int i, j, k;
String s = Double.toString(1 / Double.parseDouble(text.getText()));
for (i = 0; i < s.length(); i++)
if (s.charAt(i) == '.')
break;
for (j = i + 1; j < s.length(); j++)
if (s.charAt(j) != '0')
{
isDec = false;
break;
}
if (isDec == true)
{
String stemp = "";
for (k = 0; k < i; k++)
stemp += s.charAt(k);
text.setText(stemp);
}
else
text.setText(s);
}
clear=false;
}
if(temp==qiuyi)
{
text.setText("0");
clear=false;
}
if (temp == fu)
{ //导师,此方法参考书中例子
boolean isNumber = true;
String s = text.getText();
for (int i = 0; i < s.length(); i++)
if (! (s.charAt(i) >= '0' && s.charAt(i) <= '9' || s.charAt(i) == '.' ||
s.charAt(i) == '-'))
{
isNumber = false;
break;
}
if (isNumber == true)
{
//如果当前字符串首字母有'-'号,代表现在是个负数,再按下时,则将首符号去掉
if (s.charAt(0) == '-')
{
text.setText("");
for (int i = 1; i < s.length(); i++)
{
char a = s.charAt(i);
text.setText(text.getText() + a);
}
}
//如果当前字符串第一个字符不是符号,则添加一个符号在首字母处
else
text.setText('-' + s);
}
}

}
catch(Exception eee)
{
System.out.println("运算时,首先输入数字或字符");
text.setText("运算出错");
clear=false;
}

}
class WindowDestroyer extends WindowAdapter
{//退出窗口动作
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
class objConversion
{//导师,本进制类参考了CSMD类转换例子
public void objConversion ()
{
}
public String decDec (int decNum)
{//10

String strDecNum = Integer.toString(decNum);

for (int i = strDecNum.length(); i < 3; i++)
{
strDecNum = "0" + strDecNum;
}

// return strDecNum;
return invert (strDecNum, 5);

}
public String decHex (int decNum)
{//10 to 16

String strHexNum = "";
int currentNum = 0;

while (decNum != 0)
{

if (decNum > 15)
{

currentNum = decNum % 16;
decNum /= 16;

}
else
{

currentNum = decNum;
decNum = 0;

}

switch (currentNum)
{

case 15: strHexNum += "F";
break;
case 14: strHexNum += "E";
break;
case 13: strHexNum += "D";
break;
case 12: strHexNum += "C";
break;
case 11: strHexNum += "B";
break;
case 10: strHexNum += "A";
break;
default: strHexNum += Integer.toString(currentNum);
break;

}

}

return invert (strHexNum, 2);

}

public String decOct (int decNum)
{//10 to 8

String strOctNum = "";

while (decNum != 0)
{

if (decNum > 7)
{

strOctNum += Integer.toString(decNum % 8);
decNum /= 8;

}
else
{

strOctNum += Integer.toString(decNum);
decNum = 0;

}

}

return invert (strOctNum, 3);

}
public String decBin (int decNum)
{//10 to 2

String strBinNum = "";

while (decNum != 0)
{

if (decNum > 1)
{

strBinNum += Integer.toString(decNum % 2);
decNum /= 2;

}
else
{

strBinNum += Integer.toString(decNum);
decNum = 0;

}

}

return invert (strBinNum, 8);

}
private String invert (String strNum, int minLength) //转换长度
{

String answer = "";
int length = strNum.length();

if (length < minLength)
{

for (int padding = (minLength - length); padding > 0; padding--)
{
answer += "0";
}

}

for (int i = length; i > 0; i--)
{
answer += strNum.charAt (i - 1);
}

return answer;

}
}

public static void main(String arg[])//产生窗口
{
calculator win = new calculator();
win.setVisible(true);
}
}

Java大一的题目求大神帮忙看看怎么写TAT求源代码

哈哈~网上很多哈,GUI我也不会,现学现卖一个
package swing;import javafx.embed.swing.JFXPanel;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;/*** @author wenxy* @create 2020-05-01*/public class JavaFxDate {public static void main(String[] args) {// 创建 JFrame 实例JFrame frame = new JFrame();// Setting the width and height of frameframe.setSize(310, 180);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);/* 创建面板,这个类似于 HTML 的 div 标签* 我们可以创建多个面板并在 JFrame 中指定位置* 面板中我们可以添加文本字段,按钮及其他组件。*/JPanel panel = new JPanel();// 添加面板frame.add(panel);/** 调用用户定义的方法并添加组件到面板*/placeComponents(panel);// 设置界面可见frame.setVisible(true);}private static void placeComponents(JPanel panel) {/* 布局部分我们这边不多做介绍* 这边设置布局为 null*/panel.setLayout(null);// 创建 JLabelJLabel userLabel = new JLabel("请输入日期字符串");userLabel.setBounds(5, 5, 300, 25);panel.add(userLabel);/** 创建文本域用于用户输入*/JTextField userText = new JTextField(20);userText.setBounds(5, 40, 200, 25);panel.add(userText);// 创建 JLabelJLabel showLable = new JLabel();showLable.setBounds(5, 70, 300, 25);panel.add(showLable);// 创建登录按钮JButton loginButton = new JButton("转换");loginButton.setBounds(180, 40, 100, 25);loginButton.addActionListener(new ActionListener() {DateFormat input = new SimpleDateFormat("yyyy-MM-dd");DateFormat output = new SimpleDateFormat("yyyy年MM月dd日");{input.setLenient(false); // 设置严格按格式匹配output.setLenient(false);}@Overridepublic void actionPerformed(ActionEvent actionEvent) {try {Date date = convert(userText.getText());showLable.setText("成功:" + output.format(date));showLable.setForeground(Color.GREEN);} catch (WrongDateException e) {showLable.setText(e.getMessage());showLable.setForeground(Color.RED);}}private Date convert(String text) throws WrongDateException {try {return input.parse(text);} catch (ParseException e) {throw new WrongDateException(text);}}});panel.add(loginButton);}static class WrongDateException extends Exception {WrongDateException(String s) {super(s + "不是合法的日期字符串");}}}

阅读更多 >>>  java语言程序设计答案,国开Java语言程序设计形考4答案谁有?

JAVA课程设计,急求啊!跪求各位大神解救TAT

课程设计这么简单?是练习来的吧
JAVA设计简单 帮你包办了 绝对效率。
求啊!跪求各位大神解救TAT
比武
建数据库和数据表语句如下, 可以在sql 2000 2005 2008里面执行
create database shoolDB;use shoolDB;create table student( stuID varchar(20) , sname varchar(20), sclass varchar(20), sage int, ssex varchar(10))insert into student values('1200101011', '张红', '软件1班', 19, '男');insert into student values('1200101013', '王林', '会计2班', 20, '女');insert into student values('1200101014', '李红', '计算1班', 19, '男');insert into student values('1200101017', '王静天', '软件1班', 21, '男');java工程里面需要导入sql的jar驱动包,
java代码如下:
import java.io.FileNotFoundException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;/** * java读取数据库内容并输出 * @author young * */public class SQLToJavaTest { public static void main(String[] args) throws FileNotFoundException { // 定义数据库驱动 String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 数据库连接URL String url = "jdbc:sqlserver://localhost:1433;DatabaseName = shoolDB"; Connection conn = null; try { // 加载数据库驱动 Class.forName(driver); // 创建数据库连接 conn = DriverManager.getConnection(url, "sa", "1234"); // 创建预编译SQL对象 PreparedStatement ps = conn .prepareStatement("select * from student"); // 执行SQL,获取结果集rs ResultSet rs = ps.executeQuery(); // 处理结果集 System.out.println("学生信息为:"); while (rs.next()) { System.out.println("学号: " + rs.getString("stuID") + ". 姓名: " + rs.getString("sname") + ". 班级: " + rs.getString("sclass") + ". 年龄: " + rs.getInt("sage") + ". 性别:" + rs.getString("ssex")); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("加载数据库失败"); System.exit(1); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("数据库连接错误"); System.exit(1); } finally { if (conn != null) { try { // 关闭数据库连接 conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }}

高分求两个简单的JAVA设计源代码

wuzhikun12真好人,他的代码,我看过了,基本上是没有问题的,LZ可以试一下。还有,三四楼的要教孩子自己回家教去吧,这里是百度知道,不是百度说教。人家能问出来,自然有人家的道理,你不会或者不想答,就一边去嘛。说那么废话干吗?不就回个帖赚两分嘛。
我写的是第一题,不知道行不行。
代码写在一个Java文件中:
import java.util.*;
public class Student implements Comparator
{
private String stuNo; //学号
private String name; //姓名
private double engScore; //英语成绩
private double mathScore; //数学成绩
private double comScore; //计算机成绩
private double sum; //总成绩
//计算评测成绩
public double testScore(){
return (this.getEngScore()+this.getMathScore()+this.getComScore())/3;
}
//计算总成绩
public double sum(){
return this.getEngScore()+this.getMathScore()+this.getComScore();
}
//实现compare方法
public int compare(Object object1,Object object2){
Student student1 = (Student)object1;
Student student2 = (Student)object2;
return student1.getSum() > student2.getSum() ? 1 : student1.getSum() < student2.getSum() ? -1 : 0 ;
}
//重写toString方法
public String toString(){
return "学号:"+this.getStuNo()+" 姓名:"+this.getName()+" 英语成绩:"+this.getEngScore()+" 数学成绩:"+this.getMathScore()+" 计算机成绩:"+this.getComScore()+" 总成绩:"+this.getSum();
}
//重写equals方法
public boolean equals(Object object){
if(object == null){
return false;
}
if(!(object instanceof Student)){
return false;
}
Student student = (Student)object;
if(student.getStuNo().equals(this.getStuNo()) && student.getName().equals(this.getName()) && student.getEngScore() == this.getEngScore() && student.getMathScore() == this.getMathScore() && student.getComScore() == this.getComScore() && student.getSum() == this.getSum()){
return true;
}
return true;
}
//getter和setter方法
public void setStuNo(String stuNo){
this.stuNo = stuNo;
}
public void setName(String name){
this.name = name;
}
public void setEngScore(double engScore){
this.engScore = engScore;
this.sum = this.sum();
}
public void setMathScore(double mathScore){
this.mathScore = mathScore;
this.sum = this.sum();
}
public void setComScore(double comScore){
this.comScore = comScore;
this.sum = this.sum();
}
public void setSum(double sum){
this.sum = sum;
}
public String getStuNo(){
return stuNo;
}
public String getName(){
return name;
}
public double getEngScore(){
return engScore;
}
public double getMathScore(){
return mathScore;
}
public double getComScore(){
return comScore;
}
public double getSum(){
return sum;
}
//无参构造方法
public Student(){}
//有参构造方法
public Student(String stuNo,String name,double engScore,double mathScore,double comScore){
this.stuNo = stuNo;
this.name = name;
this.engScore = engScore;
this.mathScore = mathScore;
this.comScore = comScore;
}
public Student(String stuNo,String name,double engScore,double mathScore,double comScore,double sum){
this(stuNo,name,engScore,mathScore,comScore);
this.sum = sum;
}
}
//班长子类
class StudentBZ extends Student
{
private String duty;//责任
public StudentBZ(){}
public StudentBZ(String stuNo,String name,double engScore,double mathScore,double comScore){
super(stuNo,name,engScore,mathScore,comScore);
}
public StudentBZ(String stuNo,String name,double engScore,double mathScore,double comScore,double sum){
super(stuNo,name,engScore,mathScore,comScore,sum);
}
public String getDuty(){
return duty;
}
public void setDuty(String duty){
this.duty = duty;
}
//重写testScore方法
public double testScore(){
return (this.getEngScore()+this.getMathScore()+this.getComScore())/3 + 5;
}
}
//学委子类
class StudentXW extends Student
{
private String duty;//责任
public String getDuty(){
return duty;
}
public void setDuty(String duty){
this.duty = duty;
}
public StudentXW(String stuNo,String name,double engScore,double mathScore,double comScore){
super(stuNo,name,engScore,mathScore,comScore);
}
public StudentXW(String stuNo,String name,double engScore,double mathScore,double comScore,double sum){
super(stuNo,name,engScore,mathScore,comScore,sum);
}
//重写testScore方法
public double testScore(){
return (this.getEngScore()+this.getMathScore()+this.getComScore())/3 + 3;
}
}
//测试类
class Test
{
public static void main(String[] args){
//Student(String stuNo,String name,double engScore,double mathScore,double comScore,double sum)
//生成若干个student类、StudentXW类、StudentBZ类
Student student1 = new Student("s001","张三",70.5,50,88.5);
Student student2 = new Student("s002","李四",88,65,88.5);
Student student3 = new Student("s003","王五",67,77,90);
StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);
StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);
Student[] students = {student1,student2,student3,student4,student5};
for(int i = 0 ; i
<students.length; i++){
double avgScore = students[i].testScore();

System.out.println("第"+(i+1)+"个学生的评测成绩为:"+ avgScore+"分");

}

}

}

上面 wuzhikun12同学写的不错,但我想还不能运行,并且还不太完善。我给个能运行的:(注意:文件名为:Test.java)

//要实现对象间的比较,就必须实现Comparable接口,它里面有个compareTo方法

//Comparable最好使用泛型,这样,无论是速度还是代码量都会减少

@SuppressWarnings("unchecked")

class Student implements Comparable

{

private String studentNo; //学号

private String studentName; //姓名

private double englishScore; //英语成绩

private double computerScore; //计算机成绩

private double mathScore; //数学成绩

private double totalScore; //总成绩

//空构造函数

public Student() {}

//构造函数

public Student(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {

this.studentNo = studentNo;

this.studentName = studentName;

this.englishScore = englishSocre;

this.computerScore = computerScore;

this.mathScore = mathScore;

}

//计算总成绩

public double sum() {

this.totalScore = englishScore+computerScore+mathScore;

return totalScore;

}

//计算评测成绩

public double testScore() {

return sum()/3;

}

//实现compareTO方法

@Override

public int compareTo(Student student) {

double studentTotal = student.getTotalScore();

return totalScore==studentTotal?0:(totalScore>studentTotal?1:-1);

}

//重写toString方法

public String toString(){

return "学号:"+this.getStudentNo()+" 姓名:"+this.getStudentName()+" 英语成绩:"+this.getEnglishScore()+" 数学成绩:"+this.getMathScore()+" 计算机成绩:"+this.getComputerScore()+" 总成绩:"+this.getTotalScore();

}

//重写equals方法

public boolean equals(Object obj) {

if(obj == null){

return false;

}

if(!(obj instanceof Student)){

return false;

}

Student student = (Student)obj;

if(this.studentNo.equals(student.getStudentName())) { //照现实来说,比较是不是同一个学生,应该只是看他的学号是不是相同

return true;

} else {

return false;

}

}

/*以下为get和set方法,我个人认为,totalScore的set的方法没必要要,因为它是由其它成绩计算出来的

在set方法中,没设置一次值,调用一次sum方法,即重新计算总成绩

*/

public String getStudentNo() {

return studentNo;

}

public void setStudentNo(String studentNo) {

this.studentNo = studentNo;

sum();

}

public String getStudentName() {

return studentName;

}

public void setStudentName(String studentName) {

this.studentName = studentName;

sum();

}

public double getEnglishScore() {

return englishScore;

}

public void setEnglishScore(double englishScore) {

this.englishScore = englishScore;

sum();

}

public double getComputerScore() {

return computerScore;

}

public void setComputerScore(double computerScore) {

this.computerScore = computerScore;

sum();

}

public double getMathScore() {

return mathScore;

}

public void setMathScore(double mathScore) {

this.mathScore = mathScore;

sum();

}

public double getTotalScore() {

return totalScore;

}

}

//Student子类学习委员类的实现

class StudentXW extends Student {

//重写父类Student的testScore()方法

@Override

public double testScore() {

return sum()/3+3;

}

public StudentXW() {}

//StudentXW的构造函数

public StudentXW(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {

super(studentNo,studentName,englishSocre,computerScore,mathScore);

}

}

//Student子类班长类的实现

class StudentBZ extends Student {

//重写父类Student的testScore()方法

@Override

public double testScore() {

return sum()/3+5;

}

public StudentBZ() {}

//StudentXW的构造函数

public StudentBZ(String studentNo,String studentName,double englishSocre,double computerScore,double mathScore) {

super(studentNo,studentName,englishSocre,computerScore,mathScore);

}

}

//测试类

public class Test {

public static void main(String[] args) {

//生成若干个student类、StudentXW类、StudentBZ类

Student student1 = new Student("s001","张三",70.5,50,88.5);

Student student2 = new Student("s002","李四",88,65,88.5);

Student student3 = new Student("s003","王五",67,77,90);

StudentXW student4 = new StudentXW("s004","李六",99,88,99.5);

StudentBZ student5 = new StudentBZ("s005","朱漆",56,65.6,43.5);

Student[] students = {student1,student2,student3,student4,student5};

for(int i = 0 ; i
<students.length; i++){
double avgScore = students[i].testScore();

System.out.println(students[i].getStudentName()+"学生的评测成绩为:"+ avgScore+"分");

}

}

}

运行结果为:

张三学生的评测成绩为:69.66666666666667分

李四学生的评测成绩为:80.5分

王五学生的评测成绩为:78.0分

李六学生的评测成绩为:98.5分

朱漆学生的评测成绩为:60.03333333333333分

java 程序设计

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class mypanel extends Panel implements MouseListener
{
int chess[][] = new int[11][11];
boolean Is_Black_True;
mypanel()
{
Is_Black_True = true;
for(int i = 0;i < 11;i++)
{
for(int j = 0;j < 11;j++)
{
chess[i][j] = 0;
}
}
addMouseListener(this);
setBackground(Color.BLUE);
setBounds(0, 0, 360, 360);
setVisible(true);
}
public void mousePressed(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
if(x < 25 || x > 330 + 25 ||y < 25 || y > 330+25)
{
return;
}
if(chess[x/30-1][y/30-1] != 0)
{
return;
}
if(Is_Black_True == true)
{
chess[x/30-1][y/30-1] = 1;
Is_Black_True = false;
repaint();
Justisewiner();
return;
}
if(Is_Black_True == false)
{
chess[x/30-1][y/30-1] = 2;
Is_Black_True = true;
repaint();
Justisewiner();
return;
}
}
void Drawline(Graphics g)
{
for(int i = 30;i <= 330;i += 30)
{
for(int j = 30;j <= 330; j+= 30)
{
g.setColor(Color.WHITE);
g.drawLine(i, j, i, 330);
}
}
for(int j = 30;j <= 330;j += 30)
{
g.setColor(Color.WHITE);
g.drawLine(30, j, 330, j);
}

阅读更多 >>>  腾讯都用什么编程语言了

}
void Drawchess(Graphics g)
{
for(int i = 0;i < 11;i++)
{
for(int j = 0;j < 11;j++)
{
if(chess[i][j] == 1)
{
g.setColor(Color.BLACK);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
if(chess[i][j] == 2)
{
g.setColor(Color.WHITE);
g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16);
}
}
}
}
void Justisewiner()
{
int black_count = 0;
int white_count = 0;
int i = 0;

for(i = 0;i < 11;i++)//横向判断
{
for(int j = 0;j < 11;j++)
{
if(chess[i][j] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i][j] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
for(i = 0;i < 11;i++)//竖向判断
{
for(int j = 0;j < 11;j++)
{
if(chess[j][i] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[j][i] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}

for(i = 0;i < 7;i++)//左向右斜判断
{
for(int j = 0;j < 7;j++)
{
for(int k = 0;k < 5;k++)
{
if(chess[i + k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i + k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}
for(i = 4;i < 11;i++)//右向左斜判断
{
for(int j = 6;j >= 0;j--)
{
for(int k = 0;k < 5;k++)
{
if(chess[i - k][j + k] == 1)
{
black_count++;
if(black_count == 5)
{
JOptionPane.showMessageDialog(this, "黑棋胜利");
Clear_Chess();
return;
}
}
else
{
black_count = 0;
}
if(chess[i - k][j + k] == 2)
{
white_count++;
if(white_count == 5)
{
JOptionPane.showMessageDialog(this, "白棋胜利");
Clear_Chess();
return;
}
}
else
{
white_count = 0;
}
}
}
}

}
void Clear_Chess()
{
for(int i=0;i<11;i++)
{
for(int j=0;j<11;j++)
{
chess[i][j]=0;
}
}
repaint();
}
public void paint(Graphics g)
{
Drawline(g);
Drawchess(g);
}
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e){}

}
class myframe extends Frame implements WindowListener
{
mypanel panel;
myframe()
{
setLayout(null);
panel = new mypanel();
add(panel);
panel.setBounds(0,23, 360, 360);
setTitle("单人版五子棋");
setBounds(200, 200, 360, 383);
setVisible(true);
addWindowListener(this);

}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowDeactivated(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
public class mywindow
{
public static void main(String argc [])
{
myframe f = new myframe();
}
}
之前有人问过同样的问题,我回答的,你们是不是同一个系的,要做课程设计?我直接粘贴过来:
我自己写了一个简单的程序,可选择落子的先后顺序,重新开始,最后判断某一方是否为五子连珠。选择落子的先后顺序,只需定义一个boolean变量,每次切换取其反值;重制棋盘或重新开始就把棋盘重新绘制一遍;判断某一方是否为五子连珠,就判断某方的每个棋子,以它为中心与之紧邻的水平,垂直,左斜,右斜四个方向是否有五子连珠。用一个二维数组position存储棋盘上的棋子情况,position[x][y]=1,0,-1分别表示棋盘的第x行第y列下有黑子,无子,白子。源代码如下:
package com.test;
import java.awt.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
public class MyFiveChess {
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
f.setSize(screenWidth / 2, screenHeight / 2);
f.setLocation(screenWidth / 4, screenHeight / 4);
f.setTitle("FiveChess");
MyPanel panel = new MyPanel();
f.add(panel);
f.setVisible(true);
}
}
class MyPanel extends JPanel {
private static final int SIDELENGTH = 10;
private ArrayList

squares = new ArrayList

();;

private Ellipse2D current = null;

JButton jb = new JButton("重新开始");

JButton jb2 = new JButton("切换先手");

boolean isBlack;

boolean first = true;

boolean isOver;

int l = 16;

int n = 20;

int bx = 20;

int by = 20;

int[][] position = new int[n + 1][n + 1];

public MyPanel(){

jb.addActionListener(new MyActionHandler());

jb2.addActionListener(new MyActionHandler());

addMouseListener(new MouseHandler());

addMouseMotionListener(new MouseMotionHandler());

add(jb);

add(jb2);

}

public void initMyPenal(){

squares = new ArrayList

();

current = null;

isBlack = first;

isOver = false;

position = new int[n + 1][n + 1];

for(int i = 0; i <= n; i++)

for(int j = 0; j <= n; j++)

position[i][j] = 0;

repaint();

}

public void paint(Graphics g) {

super.paint(g);

jb.setLocation(400,150);

jb2.setLocation(400,200);

g.setColor(Color.RED);

g.setFont(new Font(null, Font.BOLD, 20));

g.drawString((first ? "黑" : "白")+"方下子", 400, 100);

g.setColor(new Color(240, 210, 120));

g.fillRect(bx - l, by - l, l * (n + 2), l * (n + 2));

g.setColor(Color.BLACK);

for (int i = 0; i <= n; i++){

g.drawLine(bx, by + i * l, bx + l * n, by + i * l);

g.drawLine(bx + i * l, by, bx + i * l, by + l * n);

}

Graphics2D g2 = (Graphics2D)g;

isBlack = first;

for(Ellipse2D r : squares){

g2.setColor(isBlack ? Color.BLACK : Color.WHITE);

g2.fill(r);

isBlack = !isBlack;

}

if(isOver) {

g.setColor(Color.RED);

g.setFont(new Font("TimesRoman", Font.BOLD, 60));

g.drawString((isBlack ? "白" : "黑") + "方获胜", 120, 200);

}

}

public Ellipse2D find(Point2D p){

for(Ellipse2D r : squares)

if(r.contains(p))

return r;

return null;

}

public void add(Point2D p) {

if(p.getX() > bx - l / 2 && p.getX() < bx + l * n + l / 2 &&

p.getY() > by - l / 2 && p.getY() < by + l * n + l / 2){

for (int i = 0; i <= n; i++) {

for (int j = 0; j <= n; j++) {

if(position[i][j] == 1 || position[i][j] == -1) continue;

current = new Ellipse2D.Double(bx + j * l - l / 2,

by + i * l - l / 2, l, l);

if (current.contains(p)) {

position[i][j] = isBlack ? 1 : -1;

isOver = isWin(position, isBlack, i , j) ? true : false;

current.setFrame(bx + j * l - l / 2 + 1,

by + i * l - l / 2 + 1, l - 2, l - 2);

squares.add(current);

repaint();

return;

}

}

}

}

}

private class MouseHandler extends MouseAdapter{

public void mousePressed(MouseEvent event){

if(isOver) return;

current = find(event.getPoint());

if(current == null)

add(event.getPoint());

}

}

private class MyActionHandler implements ActionListener{

public void actionPerformed(ActionEvent e) {

String cmd=e.getActionCommand();

if("重新开始".equals(cmd)){

initMyPenal();

}else if("切换先手".equals(cmd)){

initMyPenal();

first=!first;

}

}

}

private class MouseMotionHandler implements MouseMotionListener{

public void mouseMoved(MouseEvent event){

Rectangle r = new Rectangle(bx - l, by - l, l * (n + 2), l * (n + 2));

if(r.contains(event.getPoint())){

setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

}else setCursor(Cursor.getDefaultCursor());

}

public void mouseDragged(MouseEvent event){}

}

public boolean isWin(int[][] state, boolean isBlack, int x, int y) {//四个方向中是否有五子连珠

return isCzWin(state, isBlack, x, y)

|| isSpWin(state, isBlack, x, y)

|| isYxWin(state, isBlack, x, y)

|| isZxWin(state, isBlack, x, y);

}

public boolean isCzWin(int[][] state, boolean isBlack, int x, int y) {//判断垂直方向是否有五子连珠

int n = 0;

int a = (x >= 4 ? x - 4 : 0);

int b = (x <= state.length - 5 ? x + 4 : state.length - 1);

for (int i = a; i <= b; i++)

if (state[i][y] == (isBlack ? 1: -1)) {

if (++n == 5) return true;

} else n = 0;

return false;

}

public boolean isSpWin(int[][] state, boolean isBlack, int x, int y) {//判断水平方向是否有五子连珠

int n = 0;

int a = (y >= 4 ? y - 4 : 0);

int b = (y <= state[0].length - 5 ? y + 4 : state[0].length - 1);

for (int i = a; i <= b; i++)

if (state[x][i] == (isBlack ? 1: -1)) {

if (++n == 5) return true;

} else n = 0;

return false;

}

public boolean isZxWin(int[][] state, boolean isBlack, int x, int y) {//判断左斜方向是否有五子连珠

int n = 1, a = x, b = y;

for (int i = 1; i <= 4 && a > 0 && b > 0; i++)

if (state[a - 1][b - 1] == (isBlack ? 1: -1)) {

n++; a--; b--;

} else break;

for (int i = 1; i <= 4 && x < state.length - 1 && y < state[0].length - 1; i++)

if (state[x + 1][y + 1] == (isBlack ? 1: -1)) {

n++; x++; y++;

} else break;

if (n >= 5) return true;

return false;

}

public boolean isYxWin(int[][] state, boolean isBlack, int x, int y) {//判断右斜方向是否有五子连珠

int n = 1, a = x, b = y;

for (int i = 1; i <= 4 && a > 0 && b < state[0].length - 1; i++)

if (state[a - 1][b + 1] == (isBlack ? 1: -1)) {

n++; a--; b++;

} else break;

for (int i = 1; i <= 4 && x < state.length - 1 && y > 0; i++)

if (state[x + 1][y - 1] == (isBlack ? 1: -1)) {

n++; x++; y--;

} else break;

if (n >= 5) return true;

return false;

}

}

比较简略,自己可以根据情况修改,改进改进!

网站数据信息

"java课程设计题目及源代码,求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊~~~"浏览人数已经达到21次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:java课程设计题目及源代码,求java程序!!!大一的java课程设计题目,求高手送程序~~~求大家帮忙啊~~~的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!