導航:首頁 > 編程語言 > Java課程設計

Java課程設計

發布時間:2022-01-30 22:07:53

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課程設計

什麼程序?私信。

Ⅲ Java課程設計!急!!!(高分)

我幫你編寫了一部分,實現了「輸入十個同學的相關信息,並在文本框中顯示」(圖形界面實現)。

要實現接下去的功能其實也真的不難的,但是真的很麻煩、很浪費時間……我就幫你做到這里了,你自己添加一下代碼就可以(或者提高懸賞的話可以考慮考慮啊!哈哈……)代碼如下:

importjava.awt.BorderLayout;

importjavax.swing.JPanel;

importjavax.swing.JFrame;

importjava.awt.Dimension;

importjavax.swing.JButton;

importjava.awt.Rectangle;

importjavax.swing.JLabel;

importjavax.swing.SwingConstants;

importjavax.swing.JScrollPane;

importjavax.swing.JTextArea;

importjavax.swing.JOptionPane;

{

=1L;

privateJPaneljContentPane=null;

privateJButtonjButton=null;

privateJLabeljLabel=null;

privateJScrollPanejScrollPane=null;

privateJTextAreajTextArea=null;

/**

*Thisisthedefaultconstructor

*/

publicTongJi(){

super();

initialize();

}

/**

*Thismethodinitializesthis

*

*@returnvoid

*/

privatevoidinitialize(){

this.setSize(412,372);

this.setContentPane(getJContentPane());

this.setTitle("成績統計");

this.addWindowListener(newjava.awt.event.WindowAdapter(){

publicvoidwindowClosing(java.awt.event.WindowEvente){

System.exit(0);

}

});

this.setVisible(true);

}

/**

*

*

*@returnjavax.swing.JPanel

*/

privateJPanelgetJContentPane(){

if(jContentPane==null){

jLabel=newJLabel();

jLabel.setBounds(newRectangle(18,66,65,18));

jLabel.setHorizontalAlignment(SwingConstants.CENTER);

jLabel.setText("統計結果:");

jContentPane=newJPanel();

jContentPane.setLayout(null);

jContentPane.add(getJButton(),null);

jContentPane.add(jLabel,null);

jContentPane.add(getJScrollPane(),null);

}

returnjContentPane;

}

/**

*ThismethodinitializesjButton

*

*@returnjavax.swing.JButton

*/

privateJButtongetJButton(){

if(jButton==null){

jButton=newJButton();

jButton.setBounds(newRectangle(18,16,86,28));

jButton.setText("開始統計");

jButton.addActionListener(newjava.awt.event.ActionListener(){

publicvoidactionPerformed(java.awt.event.ActionEvente){

/////錄入成績信息

String[][]mymsg=newString[10][6];

for(inti=0;i<10;i++){

Stringstrnum=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的學號","信息錄入",JOptionPane.WARNING_MESSAGE);

Stringstrname=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的姓名","信息錄入",JOptionPane.WARNING_MESSAGE);

Stringdoublemath=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的數學成績","信息錄入",JOptionPane.WARNING_MESSAGE);

Stringdoubleeng=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的英語成績","信息錄入",JOptionPane.WARNING_MESSAGE);

Stringdoublejava=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的JAVA成績","信息錄入",JOptionPane.WARNING_MESSAGE);

Stringdoublecomp=JOptionPane.showInputDialog(null,"請輸入第"+(i+1)+"個學生的計算機成績","信息錄入",JOptionPane.WARNING_MESSAGE);

mymsg[i][0]=strnum;

mymsg[i][1]=strname;

mymsg[i][2]=doublemath;

mymsg[i][3]=doubleeng;

mymsg[i][4]=doublejava;

mymsg[i][5]=doublecomp;

}

////顯示成績信息

jTextArea.setText("學號姓名數學英語JAVA計算機");

for(inti=0;i<10;i++){

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

for(intj=0;j<6;j++){

jTextArea.setText(jTextArea.getText()+mymsg[i][j]+"");

}

}

}

});

}

returnjButton;

}

/**

*

*

*@returnjavax.swing.JScrollPane

*/

(){

if(jScrollPane==null){

jScrollPane=newJScrollPane();

jScrollPane.setBounds(newRectangle(18,86,370,230));

jScrollPane.setViewportView(getJTextArea());

}

returnjScrollPane;

}

/**

*

*

*@returnjavax.swing.JTextArea

*/

privateJTextAreagetJTextArea(){

if(jTextArea==null){

jTextArea=newJTextArea();

jTextArea.setEditable(false);

}

returnjTextArea;

}

publicstaticvoidmain(Stringargs[]){

newTongJi();

}

}//@jve:decl-index=0:visual-constraint="10,10"

效果如下圖:

Ⅳ Java課程設計

感覺不是特別麻煩。
文件系統是什麼?就是讀取個特殊文件嗎?要解碼?
界面建議你就用windowbuilder直接做吧,簡單點。
要看到結果,選擇題的好看,問題怎麼判斷。再來個論述題。
把要求寫詳細點。

Ⅳ java課程設計

去網站上下載一個,這里沒人能給你寫這么多

Ⅵ Java 課設

簡單的五子棋程序
新建一個chess類,其中代碼如下
package work;

import java.awt.Color;

public class Chess {
public static final int diamter=30;
private int x;//在網格中的索引,0~15
private int y;//在網格中的索引,0~15
private Color color;
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public Chess(int x, int y, Color color) {
super();
this.x = x;
this.y = y;
this.color = color;
}

}
然後在同一個包中新建FirstFrame類。代碼如下
package work;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

//主函數
public class FirstFrame{
public static void main(String[] args) {

FirstFrame1 f=new FirstFrame1();

f.setVisible(true);

}
}

//窗體函數
class FirstFrame1 extends JFrame implements ActionListener{
JMenuBar menuBar;
JMenu sysMenu;
JMenuItem startMenuItem;
JMenuItem backMenuItem;
JMenuItem exitMenuItem;
DrawPanel myPanel=new DrawPanel();

public FirstFrame1(){
super("娃哈哈");

add(myPanel);
menuBar=new JMenuBar();
setJMenuBar(menuBar);
sysMenu=new JMenu("系統(s)");
sysMenu.setMnemonic('s');
menuBar.add(sysMenu);
startMenuItem=new JMenuItem("開始");
backMenuItem=new JMenuItem("悔棋");
exitMenuItem=new JMenuItem("退出");
sysMenu.add(startMenuItem);
sysMenu.add(backMenuItem);
sysMenu.addSeparator();
sysMenu.add(exitMenuItem);
startMenuItem.addActionListener(this);
backMenuItem.addActionListener(this);
exitMenuItem.addActionListener(this);

super.setSize(600,650);
super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public void actionPerformed(ActionEvent e){
Object obj=e.getSource();
if(obj==startMenuItem){
myPanel.start(); //DrawPanel p=new DrawPanel();是錯的;
}else if(obj==backMenuItem){
myPanel.back();
}else{
System.exit(0);
}

}

}
最後新建一個DrawPanel類代碼如下
package work;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import sun.awt.geom.AreaOp.AddOp;

//畫柄;
class DrawPanel extends JPanel implements MouseListener,MouseMotionListener{
final int MARGIN_TOP=60;
final int MARGIN_LEFT=30;
final int CELL_WIDTH=35;
final int COLS=15;
final int ROWS=15;
Chess[] chessList=new Chess[(COLS+1)*(ROWS+1)];
int chessCount=0;
boolean isBlack=true;
boolean gameOver=false;

public DrawPanel(){ //構造函數
Color color=new Color(200,250,200);
setBackground(color);
this.addMouseMotionListener(this);
this.addMouseListener(this);
}
public void start(){
for(int i=0;i<chessList.length;i++)
chessList[i]=null;
isBlack=true;
gameOver=false;
chessCount=0;
repaint();
}
public void back(){
if (chessCount==0||gameOver==true)
return;
chessList[chessCount-1]=null;

chessCount--;
isBlack=!isBlack;

repaint();
}
@Override

protected void paintComponent(Graphics g) { //方法重寫
// TODO Auto-generated method stub
super.paintComponent(g);
for(int i=0;i<=ROWS;i++){
g.drawLine(MARGIN_LEFT, MARGIN_TOP+i*CELL_WIDTH, MARGIN_LEFT+COLS*CELL_WIDTH, MARGIN_TOP+i*CELL_WIDTH);
}
for(int i=0;i<=COLS;i++){
g.drawLine(MARGIN_LEFT+i*CELL_WIDTH, MARGIN_TOP, MARGIN_LEFT+i*CELL_WIDTH, MARGIN_TOP+ROWS*CELL_WIDTH);
}
for(int i=0;i<chessCount;i++){ //繪制棋子數組
Chess chess=chessList[i];
int xPos=MARGIN_LEFT+CELL_WIDTH*chess.getX()-Chess.diamter/2;
int yPos=MARGIN_TOP+CELL_WIDTH*chess.getY()-Chess.diamter/2;
g.setColor(chess.getColor());
g.fillOval(xPos,yPos, Chess.diamter, Chess.diamter);
if(i==chessCount-1){
g.setColor(Color.red);
g.drawRect(xPos, yPos, Chess.diamter, Chess.diamter);
}
}
if(isBlack)
g.setColor(Color.black);
else
g.setColor(Color.white);
g.fillOval(8*CELL_WIDTH, CELL_WIDTH/2,Chess.diamter, Chess.diamter);
String colorStr=isBlack==false?"白方下":"黑方下";
g.setColor(Color.blue);
g.drawString(colorStr+" 第"+chessCount/2+"步", 9*CELL_WIDTH, CELL_WIDTH);
}

public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {}

public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub
super.setCursor(new Cursor(Cursor.HAND_CURSOR));
int x=(e.getX()-MARGIN_LEFT+Chess.diamter/2)/CELL_WIDTH;
int y=(e.getY()-MARGIN_TOP+Chess.diamter/2)/CELL_WIDTH;
if(x<0||y<0||x>COLS||y>ROWS) //超出棋盤邊界
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

if(findChess(x,y)) //下過的地方不能再下
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if(gameOver)
super.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}

public void mousePressed(MouseEvent e) {

int x=(e.getX()-MARGIN_LEFT+Chess.diamter/2)/CELL_WIDTH;
int y=(e.getY()-MARGIN_TOP+Chess.diamter/2)/CELL_WIDTH;
if(x<0||y<0||x>COLS||y>ROWS) //超出棋盤邊界
return;
Color color=Color.black;
if(!isBlack) // 變顏色
color=Color.white;
if(findChess(x,y)) //下過的地方不能再下
return;
if(gameOver)
return;
chessList[chessCount]=new Chess(x,y,color);
repaint(); //重繪
isBlack=!isBlack;
chessCount++;
String colorStr=color==Color.white?"白方":"黑方";
int[] count={0,0,0,0};
for(int i=x-1;i>=0;i--){
if(findChess(i,y,color)){
count[0]++;
}
else
break;
}
for(int i=x+1;i<=COLS;i++){
if(findChess(i,y,color)){
count[0]++;
}
else
break;
}
for(int i=y-1;i>=0;i--){
if(findChess(x,i,color)){
count[1]++;
}
else
break;
}
for(int i=y+1;i<=ROWS;i++){
if(findChess(x,i,color)){
count[2]++;
}
else
break;
}
for(int i=x+1,j=y+1;i<=COLS&&j<=ROWS;i++,j++){
if(findChess(i,j,color)){
count[3]++;
}
else
break;
}
for(int i=x-1,j=y-1;i>=0&&j>=0;i--,j--){
if(findChess(i,j,color)){
count[3]++;
}
else
break;
}
for(int i=x+1,j=y-1;i<=COLS&&j>=0;i++,j--){

if(findChess(i,j,color)){
count[3]++;
}
else
break;
}
for(int i=x-1,j=y+1;i>=0&&j<=ROWS;i--,j++){
if(findChess(i,j,color)){
count[3]++;
}
else
break;
}
for(int i=0;i<4;i++){

if(count[i]>=4){
gameOver=true;
JOptionPane.showMessageDialog(this, "恭喜"+colorStr+"勝利");
return;
}
}
System.out.println(e.getX()+","+e.getY());

}

public boolean findChess(int x,int y){
for(int i=0;i<chessCount;i++){
if(chessList[i].getX()==x && chessList[i].getY()==y)
return true;
}
return false;
}

public boolean findChess(int x,int y,Color color){
for(int i=0;i<chessCount;i++){
if(chessList[i].getX()==x && chessList[i].getY()==y && chessList[i].getColor()==color)
return true;
}
return false;
}

}

Ⅶ java課程設計----記事本

//package net.src.net;

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.color.*;
import java.awt.font.*;
import javax.swing.undo.*;

public class Note extends JFrame
{
boolean isChange=false;
boolean wasChange=false;
JMenuBar menuBar=new JMenuBar();

JMenu menuFile=new JMenu("File");
JMenuItem menuFileOpen=new JMenuItem("Open..");
JMenuItem menuFileSave=new JMenuItem("Save..");
JMenuItem menuFileExit=new JMenuItem("Exit");

JMenu menuEdit=new JMenu("Edit");
JMenuItem menuFileCut=new JMenuItem("Cut");
JMenuItem font=new JMenuItem("Font");
JMenuItem menuFilePaste=new JMenuItem("Paste");

JTextArea fileArea=new JTextArea();

public Note()
{
this.setTitle("記事本");
Toolkit tool=this.getToolkit();//窗口圖標!
Image myimage=tool.getImage("戒指.jpg");
this.setIconImage(myimage);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
exit();
}
});
menuFileOpen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileOpen_actionPerformed(e);
}
});
menuFileSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileSave_actionPerformed(e);
}
});
menuFileExit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileExit_actionPerformed(e);
}
});
menuFileCut.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
fileCut_actionPerformed(e);
}
});
menuFilePaste.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
filePaste_actionPerformed(e);
}
});
font.addActionListener(new ActionListener ()
{
public void actionPerformed(ActionEvent e)
{
fileColor_actionPerformed(e);
}
});
fileArea.getDocument().addDocumentListener(new DocumentListener()
{
public void insertUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void removeUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void changedUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
});
setSize(500,450);
menuBar.add(menuFile);
menuFile.setMnemonic('F');
menuBar.add(menuEdit);
menuEdit.setMnemonic('E');
menuFile.add(menuFileOpen);
menuFileOpen.setMnemonic('O');//訪問健;
menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));//快捷健;
menuFile.add(menuFileSave);
menuFileSave.setMnemonic('S');
menuFileSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
menuFile.addSeparator();
menuFile.add(menuFileExit);
menuFileExit.setMnemonic('E');
menuEdit.add(menuFileCut);
menuFileCut.setMnemonic('C');
menuFileCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
menuEdit.add(menuFilePaste);
menuFilePaste.setMnemonic('P');
menuFilePaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK));
menuEdit.add(font);
font.setMnemonic('N');
font.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
this.getContentPane().add(new JScrollPane(fileArea));
setJMenuBar(menuBar);
fileArea.setLineWrap(true);
}
public void fileExit_actionPerformed(ActionEvent e)
{
System.exit(0);
}
public void fileOpen_actionPerformed(ActionEvent e)
{
//以下是filter;
JFileChooser fileChooser=new JFileChooser();
//fileChooser.addChoosableFileFilter(new myFilter("*.txt","Files(*.txt)"));
fileChooser.addChoosableFileFilter(fileChooser.getFileFilter());
if(fileChooser.APPROVE_OPTION!=fileChooser.showOpenDialog(this))return;
//以下是文件讀
BufferedReader dataIn=null;
try
{
dataIn=new BufferedReader(new FileReader(fileChooser.getSelectedFile().getPath()));
String c=null;
do
{
c=dataIn.readLine();
if(c!=null)
fileArea.append(c+"\n");
}
while(c!=null);
}
catch(Exception ex)
{
System.out.println("Catch exception:"+ex.toString());
}
}
public void exit()
{
if(isChange==false)
System.exit(1);
else
{
int decision=JOptionPane.showConfirmDialog(this,"The File has Change.\n"+"Do you want to save the change?",
"Notepad",JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);
if (decision == JOptionPane.YES_OPTION)
{
//以下是將文件寫入計算機!
try {
JFileChooser fileSave = new JFileChooser();
fileSave.setDialogTitle("保存文件");
//fileSave.addChoosableFileFilter(new myFilter("*.txt","Files(*.txt)"));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if (fileSave.APPROVE_OPTION != fileSave.showSaveDialog(this))
return;
BufferedWriter dataOut = new BufferedWriter(new BufferedWriter(new
FileWriter(fileSave.getSelectedFile())));
String c = null;
do {
String str = fileArea.getText();
dataOut.write(str);
dataOut.close();
}
while (c != null);
}
catch (Exception e2) {
System.out.println("Catch exception:有錯誤!" + e2.toString());
}
}
else if (decision == JOptionPane.NO_OPTION)
System.exit(1);
else if (decision == JOptionPane.CANCEL_OPTION);
;
}
//innerclass.fileSave_actionPerformed();
}
public void fileSave_actionPerformed(ActionEvent e1)
{

//以下是將文件寫入計算機!
try
{
JFileChooser fileSave=new JFileChooser();
fileSave.setDialogTitle("保存文件" );
//fileSave.addChoosableFileFilter(new myFilter("*.txt","Files(*.txt)"));
fileSave.addChoosableFileFilter(fileSave.getFileFilter());
if(fileSave.APPROVE_OPTION!=fileSave.showSaveDialog(this))return;
BufferedWriter dataOut=new BufferedWriter(new BufferedWriter(new FileWriter(fileSave.getSelectedFile()+".txt")));
//RandomAccessFile dataOut=new RandomAccessFile(fileSave.getSelectedFile(),"rw");
String c=null;
do
{
String str=fileArea.getText();
dataOut.write(str);
dataOut.close();
}
while(c!=null);
}
catch(Exception e2)
{
System.out.println("Catch exception:有錯誤!"+e2.toString());
}
}
public static void main(String arg[])
{
Note nt=new Note();
nt.show();
}
public void fileCut_actionPerformed(ActionEvent e)
{
fileArea.cut();
}
public void filePaste_actionPerformed(ActionEvent e)
{
fileArea.paste();
}
public void fileColor_actionPerformed(ActionEvent e)
{
JColorChooser fileColor=new JColorChooser();
//fileArea.setForeground(fileColor.showDialog(this,"顏色",Color.red));
//fileArea.setSelectionColor(fileColor.showDialog(this,"顏色",Color.red));
fileArea.setSelectionColor(fileColor.showDialog(this,"顏色",Color.black));
}
}

Ⅷ java課程設計(符合要求,別太深奧)

俄羅斯方塊沒有 有自己做的貪食蛇

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class GameMain extends JFrame implements Runnable {

int runY = 140;

int runX = 120;

int width = 600;

int height = 500;

int W = 10;

int M = 10;

int fangxiang = 0;

int sheshen[] = new int[200];

int foodx = 150;

int foody = 150;

int score = 0;

boolean zhuangtai = true;

class UsurKey extends KeyAdapter {

public void keyPressed(KeyEvent e) {
fangxiang = e.getKeyCode();
}

}

class UsurMouse extends MouseAdapter {

public void mouseClicked(MouseEvent e) {
System.out.println(e.getX() + "," + e.getY());
}
}

public GameMain() {
this.setSize(width, height);
this.setVisible(true);
this.addKeyListener(new UsurKey());
this.addMouseListener(new UsurMouse());
new Thread(this).start();
for (int i = 0; i < W; i++) {
sheshen[i * 2] = runX + i * W;
sheshen[i * 2 + 1] = runY;
}
}

public static void main(String[] args) {
GameMain g = new GameMain();
}

int count = 0;

public void paint(Graphics g) {
g.fillRect(0, 0, width, height);
g.setColor(new Color(155, 155, 155));
try {
File file1 = new File("img/�0�8�0�8.jpg");
Image image = ImageIO.read(file1);
g.drawImage(image, 150, 100, null);
} catch (IOException e) {
e.printStackTrace();
}
g.drawRect(20, 50, width - 40, height - 100);
g.setColor(new Color(133, 195, 95));
for (int i = 0; i < W; i++) {
g.fillRect(sheshen[i * 2], sheshen[i * 2 + 1], 10, 10);
}
g.setColor(new Color(255,255,0));
count++;
if(count%2==0){
g.fillRect(foodx, foody, M, M);
}
}

public void updata() {
if (fangxiang == KeyEvent.VK_UP) {
runY = runY - 10;
}
if (fangxiang == KeyEvent.VK_DOWN) {
runY = runY + 10;
}
if (fangxiang == KeyEvent.VK_RIGHT) {
runX = runX + 10;
}
if (fangxiang == KeyEvent.VK_LEFT) {
runX = runX - 10;
}

for (int i = W - 1; i > 0; i--) {
sheshen[i * 2] = sheshen[(i - 1) * 2];
sheshen[i * 2 + 1] = sheshen[(i - 1) * 2 + 1];
}
sheshen[0] = runX;
sheshen[1] = runY;
if (sheshen[0] <= 20 || sheshen[0] + W >= 580) {
zhuangtai = false;
}
if (sheshen[1] <= 50 || sheshen[1] + W >= 450) {
zhuangtai = false;
}
Random rand= new Random();
if(sheshen[0]==foodx&&sheshen[1]==foody){
W++;
while(true){
foodx = Math.abs((rand.nextInt()%(50 + width-100 -10))/10*10);
foody = Math.abs((rand.nextInt()%(50 + height-100 -10))/10*10);
if(foodx>60&&foody>60){
boolean flag=true;
for(int i=0;i<W;i++){
if(sheshen[2*i] == foodx && sheshen[2*i+1] == foody){
flag=false;
}
}
if(flag){
break;
}
}
}
}
}

public void run() {
while (zhuangtai) {
try {
updata();
this.repaint();
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
}

閱讀全文

與Java課程設計相關的資料

熱點內容
高cpu雲伺服器 瀏覽:362
androidwebrtcaecm 瀏覽:981
阿里雲部署java 瀏覽:636
雲是不是就是個大的伺服器 瀏覽:581
如何建立linux日誌管理伺服器 瀏覽:772
悟空頭圖標是什麼APP 瀏覽:555
linuxandroid虛擬機 瀏覽:281
ps李濤pdf 瀏覽:638
linuxfork線程 瀏覽:97
易語言編譯改名 瀏覽:723
阿里伺服器都提供什麼 瀏覽:756
cf打開伺服器接不上怎麼辦 瀏覽:901
linux下more命令 瀏覽:402
des演算法運算位數 瀏覽:375
珠海建行貸款解壓 瀏覽:635
布穀源碼iOS 瀏覽:66
雲存儲節點伺服器是啥 瀏覽:784
壓縮文件可以用pad解壓么 瀏覽:609
我的世界伺服器如何換 瀏覽:64
程序員要拒絕嗎 瀏覽:124