百度
360搜索
搜狗搜索

java课程设计需求分析,java 课程设计???详细介绍

本文目录一览: java 计算器课程设计报告

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;//导包
class MyClass extends JFrame
//创建一个MyClass类继承JFrame框架的窗口类,
//也就是说JFrame里有的功能MyClass都能实现
{
JLabel a1=new JLabel("第一个数");
//创建一个显示“第一个数”的标签
JLabel a2=new JLabel("第二个数");
JLabel a3=new JLabel("运算结果");
JTextField b1=new JTextField(5);
//创建一个文本框、默认长度为5,用来输入运算数字,当然也可以默认为空
JTextField b2=new JTextField(5);
JTextField b3=new JTextField(5);
//创建一个用于显示运算结果的标签,也可以创建一个标签来显示
JButton a=new JButton("加");
//创建一个用于加法计算的按钮,点击时进行加法运算
JButton b=new JButton("减");
JButton c=new JButton("乘");
JButton d=new JButton("除");
JPanel jp1=new JPanel();//创建一个面板,用来放控件
JPanel jp2=new JPanel();
JPanel jp3=new JPanel();
MyClass()//构造函数,用来初始化的
{
setLayout(new GridLayout(3,1));//添加一个四行四列的布局管理器
jp1.setLayout(new FlowLayout());//设置JP1面板为流式布局管理器
jp1.setLayout(new FlowLayout());
//将a1,b1,a2,b2四个控件添加到jp1面板中
jp1.add(a1);
jp1.add(b1);
jp1.add(a2);
jp1.add(b2);
jp1.add(a3);
//将a,b,c,d四个控件添加到jp2面板中
jp2.add(a);
jp2.add(b);
jp2.add(c);
jp2.add(d);
jp3.add(a3);
jp3.add(b3);
//将jp1,jp2,jp3三个面板添加到窗口中
add(jp1);
add(jp3);
add(jp2);
Object e;
a.addActionListener(new ActionListener()
//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
//获取第一个输入数,并将其由String型转换成double型
double y=Double.valueOf(b2.getText().toString());
//获取第二个输入数,并将其由String型转换成double型
b3.setText(""+(x+y));
//将运算结果在b3这个文本框中显示
}

});
b.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
b3.setText(""+(x-y));
}

});
c.addActionListener(new ActionListener()//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
b3.setText(""+(x*y));
}

});
d.addActionListener(new ActionListener()//创建一个匿名的事件监听器
{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
double x=Double.valueOf(b1.getText().toString());
double y=Double.valueOf(b2.getText().toString());
//因为0不能做除数,所以在这里需要进行判断
if(y==0)
{
b3.setText("错误");
}
else
{
b3.setText(""+(x/y));
}
}

});
//下面的是设置窗口的属性
this.setTitle("计算器");//设置窗口的标题
//this.setSize(400,400);//设置窗口的大小,也可以改成this.pack()
this.pack();
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);//设置关闭属性
this.setVisible(true);//设置窗口的可见性
}
public static void main(String[] args)//主函数
{
new MyClass();
}
}
http://wenku.baidu.com/view/6bb6660ef12d2af90242e64c.html
这是要神马 要程序还是?

基于JAVA的学生信息管理系统

2、教学管理:教学信息管理模块主要实现各种与教学相关信息的设置和维护的操作,包括以下几方面的内容:院系设置、专业设置、年级设置、班级设置、学期设置、课程开设等
3、学籍管理:学生学籍管理模块主要实现对学生基本信息的设置和维护,提供学生信息的录入和查询页面,并对学生班级更改情况进行维护等,它包括以下几方面的内容:学生基本信息维护和查询、学生增减、批量导入学生信息并自动生成学号。
其中,学生基本信息的录入、维护和查询统计功能是每个学生必须完成的功能,而学生增减和批量导入学生信息并自动生成学号则是有能力的学生可以在时间充裕的前提下进一步完成。
4、成绩管理:学生成绩管理模块主要实现对学生选修课程以及所选课程的成绩信息的设置和维护。
它包括以下几方面的内容:学生选课管理、学生成绩管理两部分。销售管理系统的主要任务是建立、维护客户信息档案、统计、汇总产品信息,进行定单的录入、维护等。要求编写Java GUI程序实现上述功能。
3 课程设计报告书主要内容1 需求分析2 总体设计2.1 设计的总体思想与算法描述
2.2 模块结构图
2.3 各功能模块的功能与处理流程描述
2.4 界面设计
3 各功能模块程序设计
按照功能模块的功能与处理流程描述给出详细的程序代码,并给出重点语句的注释.
4 小结4 课程设计要求
1 按时到机房签到,在指定机位上机。遵守机房纪律。
2 独立完成课程设计任务。指导教师到机位上指导学生和分时段验收学生完成的程序。
3 按时提交打印的课程设计报告书。
5 课程设计参考书
1 许文宪 懂子建. Java程序设计教程与实训 北京:北京大学出版社,2005.
2 辛运帏 .Java程序设计.北京:清华大学出版社, 2004
3 蔡翠平 .Java程序设计.北京:清华大学出版社,2003

java 课程设计???

都已经说的这么清楚了
你还不会写???
//父类MyMedia
public class MyMedia{
protected String mediaName;
protected float price;
protected String press;
protected String artist;
public MyMedia(String mn,float pri,String pre,String art){
mediaName=mn;
price=pri;
press=pre;
artist=art;
}
public void mediaNameInput(String mn){
mediaName=mn;
}
public void mediaPriceInput(float pri){
price=pri;
}
public void mediaPressInput(String pre){
press=pre;
}
public void mediaArtistInput(String art){
artist=art;
}
}
//子类MyBook
public class MyBook extends MyMedia{
private String editor;
private String publishDate;
private String bookISBN;
public MyBook(String mn,float pri,String pre,String art,String edi,String pub,String isbn){
super(mn,pri,pre,art);
editor=edi;
publishDate=pub;
bookISBN=isbn;
}
public void bookOtherInfo(String edi,String pub,String isbn){
editor=edi;
publishDate=pub;
bookISBN=isbn;
}
public void getBookInfo(){
System.out.println();
System.out.println("书名: "+mediaName);
System.out.println("书的价格:"+price);
System.out.println("书的出版社:"+press);
System.out.println("书的作者:"+artist);
System.out.println("书的editor:"+editor);
System.out.println("书的出版日期:"+publishDate);
System.out.println("书的bookISBN:"+bookISBN);
}
}
//子类MyCD
public class MyCD extends MyMedia{
private String cdISRC;
private String cdPublisher;
public MyCD(String mn,float pri,String pre,String art,String isrc,String cdp){
super(mn,pri,pre,art);
cdISRC=isrc;
cdPublisher=cdp;
}
public void CDOtherInfo(String isrc,String cdp){
cdISRC=isrc;
cdPublisher=cdp;
}
public void getCDInfo(){
System.out.println();
System.out.println("CD名: "+mediaName);
System.out.println("CD的价格:"+price);
System.out.println("CD的出版社:"+press);
System.out.println("CD的演唱者:"+artist);
System.out.println("CD的cdISRC:"+cdISRC);
System.out.println("CD的发行者:"+cdPublisher);
}
}
//子类MyTape
public class MyTape extends MyMedia{
private String TapeISRC;
public MyTape(String mn,float pri,String pre,String art,String isrc){
super(mn,pri,pre,art);
TapeISRC=isrc;
}
public void TapeOtherInfo(String isrc){
TapeISRC=isrc;
}
public void getTapeInfo(){
System.out.println();
System.out.println("CD名: "+mediaName);
System.out.println("CD的价格:"+price);
System.out.println("CD的出版社:"+press);
System.out.println("CD的演唱者:"+artist);
System.out.println("CD的TapeISRC:"+TapeISRC);
}
}
未完代叙 时间太晚了!!
QQ 383513327

跪求java课程设计报告!要求:编写一个类似于windows计算器的程序,能实现加减乘除等基本运算并能处理异常

import java.awt.BorderLayout;
import java.awt.Color;
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.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
public class Jisuan extends JFrame implements ActionListener{
private JTextField reasult;
private JButton btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn0,
btnAC,btnAdd,btnSub,btnReasult,btnD,
btnAbout,btnCancel;
private boolean add,sub,end,s,c;
private String str;
private double num1,num2;
public Jisuan(){
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
TitledBorder tb=new TitledBorder("输出"); tb.setTitleColor(Color.BLUE);

阅读更多 >>>  linux开发java程序如何引入jar

btnAbout=new JButton(" 关于 ");
btnCancel=new JButton("Cancel");
btnCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ee)
{
System.exit(0);
}
});
btnAbout.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ee)
{
JOptionPane.showMessageDialog(null,"无",
"消息",JOptionPane.INFORMATION_MESSAGE);
}
});
p3.add(btnAbout);
p3.add(btnCancel);
//JPanel p4=new JPanel();
//JPanel p5=new JPanel();
//reasult.setBorder(tb);
reasult =new JTextField("0",20);
reasult.setEditable(false);
reasult.setHorizontalAlignment(JTextField.RIGHT);
reasult.setForeground(Color.BLUE);

p1.setBorder(tb);
p1.add(reasult);

btn0=new JButton("0"); btn0.addActionListener(this);
btn1=new JButton("1"); btn1.addActionListener(this);
btn2=new JButton("2"); btn2.addActionListener(this);
btn3=new JButton("3"); btn3.addActionListener(this);
btn4=new JButton("4"); btn4.addActionListener(this);
btn5=new JButton("5"); btn5.addActionListener(this);
btn6=new JButton("6"); btn6.addActionListener(this);
btn7=new JButton("7"); btn7.addActionListener(this);
btn8=new JButton("8"); btn8.addActionListener(this);
btn9=new JButton("9"); btn9.addActionListener(this);
btnD=new JButton("."); btnD.addActionListener(this); btnD.setForeground(Color.RED);
btnAC=new JButton("AC"); btnAC.addActionListener(this); btnAC.setBackground(Color.PINK);
btnAdd=new JButton("+"); btnAdd.addActionListener(this); btnAdd.setForeground(Color.BLUE);
btnSub=new JButton("—"); btnSub.addActionListener(this); btnSub.setForeground(Color.BLUE);
btnReasult=new JButton("="); btnReasult.addActionListener(this); btnReasult.setForeground(Color.RED);

p2.add(btn1);p2.add(btn2);p2.add(btn3);p2.add(btn4);p2.add(btn5);
p2.add(btn6);p2.add(btn7);p2.add(btn8);p2.add(btn9);p2.add(btn0);
p2.add(btnD);p2.add(btnAC);p2.add(btnAdd);p2.add(btnSub);p2.add(btnReasult);
p2.setLayout(new GridLayout(5,3));

add(p1,BorderLayout.NORTH);
add(p2,BorderLayout.CENTER);
add(p3,BorderLayout.SOUTH);

}
public void num(int i){
String s = null;
s=String.valueOf(i);
if(end){
//如果数字输入结束,则将文本框置零,重新输入
reasult.setText("0");
end=false;

}
if((reasult.getText()).equals("0")){
//如果文本框的内容为零,则覆盖文本框的内容
reasult.setText(s);
}

else{
//如果文本框的内容不为零,则在内容后面添加数字
str = reasult.getText() + s;
reasult.setText(str);

}
}/*
String s=null;
s=String.valueOf(i);
str=reasult.getText()+s;
reasult.setText(str);
}*/
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn1)
num(1);
else if(e.getSource()==btn2)
num(2);
else if(e.getSource()==btn3)
num(3);
else if(e.getSource()==btn4)
num(4);
else if(e.getSource()==btn5)
num(5);
else if(e.getSource()==btn6)
num(6);
else if(e.getSource()==btn7)
num(7);
else if(e.getSource()==btn8)
num(8);
else if(e.getSource()==btn9)
num(9);
else if(e.getSource()==btn0)
num(0);
else if(e.getSource()==btnAdd){
sign(1);
btnD.setEnabled(true);
}
else if(e.getSource()==btnSub){
sign(2);
btnD.setEnabled(true);
}
else if(e.getSource()==btnAC){
btnD.setEnabled(true);
reasult.setText("0");
}

else if(e.getSource()==btnD){
str=reasult.getText();
str+=".";
reasult.setText(str);
btnD.setEnabled(false);
}
else if(e.getSource()==btnReasult){

btnD.setEnabled(true);
num2=Double.parseDouble(reasult.getText());
if(add){
num1=num1 + num2;}
else if(sub){
num1=num1 - num2;}

reasult.setText(String.valueOf(num1));
end=true;
}

}
public void sign(int s){
if(s==1){
add=true;
sub=false;

}
else if(s==2){
add=false;
sub=true;

}

num1=Double.parseDouble(reasult.getText());
end=true;
}
public static void main(String[] args){
Jisuan j=new Jisuan();
j.setTitle("+/-简易计算器");
j.setLocation(500,280);
j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j.setResizable(false);
j.pack();
j.setVisible(true);
}
}
没写乘法,你自其实从网上搜索就能搜出来现成代码

!高分跪求帮忙写一个简单小程序的JAVA课程设计报告(内详!!)

连连看java源代码
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class lianliankan implements ActionListener
{
JFrame mainFrame; //主面板
Container thisContainer;
JPanel centerPanel,southPanel,northPanel; //子面板
JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组
JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮
JLabel fractionLable=new JLabel("0"); //分数标签
JButton firstButton,secondButton; //分别记录两次被选中的按钮
int grid[][] = new int[8][7];//储存游戏按钮位置
static boolean pressInformation=false; //判断是否有按钮被选中
int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标
int i,j,k,n;//消除方法控制
public void init(){
mainFrame=new JFrame("JKJ连连看");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel=new JPanel();
southPanel=new JPanel();
northPanel=new JPanel();
thisContainer.add(centerPanel,"Center");
thisContainer.add(southPanel,"South");
thisContainer.add(northPanel,"North");
centerPanel.setLayout(new GridLayout(6,5));
for(int cols = 0;cols < 6;cols++){
for(int rows = 0;rows < 5;rows++ ){
diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));
diamondsButton[cols][rows].addActionListener(this);
centerPanel.add(diamondsButton[cols][rows]);
}
}
exitButton=new JButton("退出");
exitButton.addActionListener(this);
resetButton=new JButton("重列");
resetButton.addActionListener(this);
newlyButton=new JButton("再来一局");
newlyButton.addActionListener(this);
southPanel.add(exitButton);
southPanel.add(resetButton);
southPanel.add(newlyButton);
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));
northPanel.add(fractionLable);
mainFrame.setBounds(280,100,500,450);
mainFrame.setVisible(true);
}
public void randomBuild() {
int randoms,cols,rows;
for(int twins=1;twins<=15;twins++) {
randoms=(int)(Math.random()*25+1);
for(int alike=1;alike<=2;alike++) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=randoms;
}
}
}
public void fraction(){
fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));
}
public void reload() {
int save[] = new int[30];
int n=0,cols,rows;
int grid[][]= new int[8][7];
for(int i=0;i<=6;i++) {
for(int j=0;j<=5;j++) {
if(this.grid[i][j]!=0) {
save[n]=this.grid[i][j];
n++;
}
}
}
n=n-1;
this.grid=grid;
while(n>=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
while(grid[cols][rows]!=0) {
cols=(int)(Math.random()*6+1);
rows=(int)(Math.random()*5+1);
}
this.grid[cols][rows]=save[n];
n--;
}
mainFrame.setVisible(false);
pressInformation=false; //这里一定要将按钮点击信息归为初始
init();
for(int i = 0;i < 6;i++){
for(int j = 0;j < 5;j++ ){
if(grid[i+1][j+1]==0)
diamondsButton[i][j].setVisible(false);
}
}
}
public void estimateEven(int placeX,int placeY,JButton bz) {
if(pressInformation==false) {
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
pressInformation=true;
}
else {
x0=x;
y0=y;
fristMsg=secondMsg;
firstButton=secondButton;
x=placeX;
y=placeY;
secondMsg=grid[x][y];
secondButton=bz;
if(fristMsg==secondMsg && secondButton!=firstButton){
xiao();
}
}
}
public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释
if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判断是否相邻
remove();
}
else{
for (j=0;j<7;j++ ) {
if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空
if (y>j) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边
for (i=y-1;i>=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0) {
k=0;
break;
}
else{ k=1; } //K=1说明通过了第一次验证
}
if (k==1) {
linePassOne();
}
}
if (y
<j){ 如果第二个按钮的y坐标小于空按钮的y坐标说明第一按钮在第二按钮右边
for (i=y+1;i<=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

k=0;

break;

}

else { k=1; }

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0
<x) {
for (n=x0;n<=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 && n==x-1) {

remove();

}

}

}

if (x0>x) {

for (n=x0;n>=x+1 ;n-- ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 && n==x+1) {

remove();

}

}

}

}

}

for (i=0;i<8;i++ ) { //列

if (grid[i][y0]==0) {

if (x>i) {

for (j=x-1;j>=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (x
<i) {
for (j=x+1;j<=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0
<y) {
for (n=y0;n<=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 && n==y-1) {

remove();

}

}

}

if (y0>y) {

for (n=y0;n>=y+1 ;n--) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 && n==y+1) {

remove();

}

}

}

}

}

}

}

public void linePassOne(){

if (y0>j){ //第一按钮同行空按钮在左边

for (i=y0-1;i>=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else { k=2; } //K=2说明通过了第二次验证

}

}

if (y0
<j){ 第一按钮同行空按钮在与第二按钮之间
for (i=y0+1;i<=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else{ k=2; }

}

}

}

public void rowPassOne(){

if (x0>i) {

for (j=x0-1;j>=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

if (x0
<i) {
for (j=x0+1;j<=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

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

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols < 6;cols++){

for(int rows = 0;rows < 5;rows++ ){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

我爸爸是清华大学的老师,他教我的。

我有的

hi 我

前两天刚刚帮一个人做了一个

不过他要的是图片的

你们不会是同一个学校的吧?????

连连看java源代码

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class lianliankan implements ActionListener

{

JFrame mainFrame; //主面板

Container thisContainer;

JPanel centerPanel,southPanel,northPanel; //子面板

JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组

JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮

JLabel fractionLable=new JLabel("0"); //分数标签

JButton firstButton,secondButton; //分别记录两次被选中的按钮

int grid[][] = new int[8][7];//储存游戏按钮位置

static boolean pressInformation=false; //判断是否有按钮被选中

int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标

int i,j,k,n;//消除方法控制

public void init(){

mainFrame=new JFrame("JKJ连连看");

thisContainer = mainFrame.getContentPane();

thisContainer.setLayout(new BorderLayout());

centerPanel=new JPanel();

southPanel=new JPanel();

northPanel=new JPanel();

thisContainer.add(centerPanel,"Center");

thisContainer.add(southPanel,"South");

thisContainer.add(northPanel,"North");

centerPanel.setLayout(new GridLayout(6,5));

for(int cols = 0;cols < 6;cols++){

for(int rows = 0;rows < 5;rows++ ){

diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1]));

diamondsButton[cols][rows].addActionListener(this);

centerPanel.add(diamondsButton[cols][rows]);

}

}

exitButton=new JButton("退出");

exitButton.addActionListener(this);

resetButton=new JButton("重列");

resetButton.addActionListener(this);

newlyButton=new JButton("再来一局");

newlyButton.addActionListener(this);

southPanel.add(exitButton);

southPanel.add(resetButton);

southPanel.add(newlyButton);

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())));

northPanel.add(fractionLable);

mainFrame.setBounds(280,100,500,450);

mainFrame.setVisible(true);

}

public void randomBuild() {

int randoms,cols,rows;

for(int twins=1;twins<=15;twins++) {

randoms=(int)(Math.random()*25+1);

for(int alike=1;alike<=2;alike++) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=randoms;

}

}

}

public void fraction(){

fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100));

}

public void reload() {

int save[] = new int[30];

int n=0,cols,rows;

int grid[][]= new int[8][7];

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

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

if(this.grid[i][j]!=0) {

save[n]=this.grid[i][j];

n++;

}

}

}

n=n-1;

this.grid=grid;

while(n>=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

while(grid[cols][rows]!=0) {

cols=(int)(Math.random()*6+1);

rows=(int)(Math.random()*5+1);

}

this.grid[cols][rows]=save[n];

n--;

}

mainFrame.setVisible(false);

pressInformation=false; //这里一定要将按钮点击信息归为初始

init();

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

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

if(grid[i+1][j+1]==0)

diamondsButton[i][j].setVisible(false);

}

}

}

public void estimateEven(int placeX,int placeY,JButton bz) {

if(pressInformation==false) {

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

pressInformation=true;

}

else {

x0=x;

y0=y;

fristMsg=secondMsg;

firstButton=secondButton;

x=placeX;

y=placeY;

secondMsg=grid[x][y];

secondButton=bz;

if(fristMsg==secondMsg && secondButton!=firstButton){

xiao();

}

}

}

public void xiao() { //相同的情况下能不能消去。仔细分析,不一条条注释

if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判断是否相邻

remove();

}

else{

for (j=0;j<7;j++ ) {

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (y>j) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边

for (i=y-1;i>=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0) {

k=0;

break;

}

else{ k=1; } //K=1说明通过了第一次验证

}

if (k==1) {

linePassOne();

}

}

if (y
<j){ 如果第二个按钮的y坐标小于空按钮的y坐标说明第一按钮在第二按钮右边
for (i=y+1;i<=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

k=0;

break;

}

else { k=1; }

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0
<x) {
for (n=x0;n<=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 && n==x-1) {

remove();

}

}

}

if (x0>x) {

for (n=x0;n>=x+1 ;n-- ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 && n==x+1) {

remove();

}

}

}

}

}

for (i=0;i<8;i++ ) { //列

if (grid[i][y0]==0) {

if (x>i) {

for (j=x-1;j>=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (x
<i) {
for (j=x+1;j<=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0
<y) {
for (n=y0;n<=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 && n==y-1) {

remove();

}

}

}

if (y0>y) {

for (n=y0;n>=y+1 ;n--) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 && n==y+1) {

remove();

}

}

}

}

}

}

}

public void linePassOne(){

if (y0>j){ //第一按钮同行空按钮在左边

for (i=y0-1;i>=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else { k=2; } //K=2说明通过了第二次验证

}

}

if (y0
<j){ 第一按钮同行空按钮在与第二按钮之间
for (i=y0+1;i<=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else{ k=2; }

}

}

}

public void rowPassOne(){

if (x0>i) {

for (j=x0-1;j>=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

if (x0
<i) {
for (j=x0+1;j<=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

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

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols < 6;cols++){

for(int rows = 0;rows < 5;rows++ ){

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

}

//old 998 lines

//new 318 lines

参考资料:http://zhidao.baidu.com/question/36439800.html?fr=qrl3

阅读更多 >>>  前端mvc框架有哪些,国外最常使用的前端框架(比较火的前端框架)

网站数据信息

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