當前位置:首頁 » 編程語言 » 大二java課程設計題目

大二java課程設計題目

發布時間: 2024-04-21 05:48:01

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

⑵ 璇劇▼璁捐¢樼洰錛屽氱嚎紼嬬紪紼嬶細鍖婚櫌闂ㄨ瘖妯℃嫙錛屾兂鐢╦ava瀹炵幇錛屾眰澶х炴寚鐐

鍏稿瀷鐨勭敓浜ц呮秷璐硅呮ā鍨嬨

浜嗚Вj5鐨勫苟鍙戝簱錛岄偅涓騫跺彂搴撲腑鏈夐傚悎緇勪歡瀹炵幇銆

濡傛灉涓嶄簡瑙o紝榪欎箞鏉ワ細

鍒涘緩涓涓闃熷垪錛屾ら槦鍒楄佹眰綰跨▼瀹夊叏錛屽傛灉闃熷垪涓虹┖鍒欐秷璐硅呴樆濉炪傚傛灉闃熷垪杈懼埌鏌愪釜鏈澶у礆紝鍒欓樆濉炵敓浜ц呫

闃熷垪鐢錛屾櫘閫氱殑list鎴栧疄鐜板ソ鐨勯槦鍒楀寘瑁呮垚綰跨▼瀹夊叏鐨勩

鐢╯ynchronized鍚屾ュ師鏂規硶鎴栦唬鐮佸潡銆

鍐欎竴涓鎴杗涓綰跨▼錛屾ā鎷熺棶浜猴紝鎺掗槦鍔炵悊涓氬姟錛屽線涓婇潰鐨勯槦鍒椾腑娣誨姞鏁版嵁銆

褰撹揪鍒伴槦鍒楃殑鏈澶у圭Н錛岄樆濉烇紝絳夊緟鐢熶駭鑰呯嚎紼嬪彇鏁版嵁銆

闃誨烇細makerLock.wait();//鉶氭嫙鏈轟細鍑鴻╃嚎紼嬫寕璧鳳紝鍏跺疄灝辨槸鎿嶄綔緋葷粺錛屼繚瀛樺綋鍓嶇嚎紼嬪湪cpu涓婄殑榪愯岀姸鎬併傚啀鍑鴻╃嚎紼嬫e湪浣跨敤鐨刢pu璧勬簮錛屽崰鐢ㄧ殑鍐呭瓨涓嶄細閲婃斁銆

寰闃熷垪鎻掑叆鏁版嵁鐨勬椂鍊欙紝鍥犱負涓嶇煡閬撴槸鍚︽湁娑堣垂鑰呭勪簬絳夊緟鐘舵侊紝閫氱煡娑堣垂鑰咃細

customerLock.notifyAll();//鉶氭嫙鏈鴻皟搴︽秷璐硅呯嚎紼嬭繍琛岋紝瀹為檯涓婃槸鎿嶄綔緋葷粺錛屾妸淇濆瓨鐨勬秷璐硅呯嚎紼嬬姸鎬侊紝浠庢柊鍔犺澆鍒癱pu涓鎺ョ潃榪愯屻傛帴鐫榪愯岀嚎紼嬫槸浠繪剰鐨勶紝鍙栧喅浜庝笉鍚屾搷浣滅郴緇熺殑綰跨▼璋冨害綆楁硶銆

娑堣垂鑰呯嚎紼嬭誨彇涓涓鏁版嵁鍚庯紝瑕侀氱煡鐢熶駭鑰咃紝鍙浠ョ戶緇錛岄亾鐞嗗悓涓婏細

makerLock.notifyAll();

闃熷垪涓錛屾棤鏁版嵁鍙璇葷殑鏃跺欙細

customerLock.wait();//鍘熺悊鍚屼笂錛

鏈鍚庢敞鎰忥紝鐢熶駭鑰呰窡娑堣垂鑰呬嬌鐢ㄤ簡涓や釜涓嶅悓鐨勫硅薄閿併俵ock.wait()鐨勪嬌鐢ㄦ柟娉曟槸榪欐牱鐨勶細

synchronized(lock){

......

while(condition==true){

lock.wait();

}

......

Objecto=queen.pop();

lock.notifyAll();

}

鏈鍚庡惎鍔╪涓綰跨▼璇婚槦鍒楋紝妯℃嫙鍔炵悊涓氬姟鐨勭獥鍙o紱n涓綰跨▼鍐欓槦鍒楋紝妯℃嫙鐥呬漢鎺掗槦銆

鏂扮嚎紼嬪簱涔熸湁璺熻佺嚎紼嬪簱瀵瑰簲鐨勬柟娉曪紝鏂扮嚎紼嬪簱鏈夌嚎紼嬪畨鍏ㄧ殑楂樻晥闃熷垪銆傛病鏈変笂闈㈤夯鐑︼紝浣嗕笂闈㈠啓鐨勬槸鐞嗚В鏂扮嚎紼嬫暟鎹緇撴瀯涓庡疄鐜扮殑鍩虹銆

packagecom.;

importjava.util.LinkedList;
importjava.util.List;
importjava.util.Random;

publicclassTestThread2{

//緙撳啿涓婇檺
privatelongbufsize;

//緙撳啿
privateList<String>buf;

publicTestThread2(){
bufsize=5;
buf=newLinkedList<String>();
}

//鐢熶駭鑰呰皟鐢
publicvoidput(Strings){
//妯℃嫙鐢熶駭鑰呰窡涓嶄笂娑堣垂鑰
/*
try{
Thread.sleep(100);
}catch(InterruptedExceptione){
}
*/

synchronized(this){
//瓚呰繃闃熷垪闄愬埗灝辯瓑寰
while(buf.size()==bufsize){
System.out.println("闃熷垪宸叉弧錛岀敓浜ц:"+Thread.currentThread().getId()+"寮濮嬬瓑寰呫");
try{
this.wait();
}catch(InterruptedExceptione){
}
}

buf.add(s);

//閫氱煡娑堣垂鑰
this.notifyAll();
}

}

//娑堣垂鑰呰皟鐢
synchronizedpublicStringtake(){

//妯℃嫙娑堣垂鑰呰窡涓嶄笂鐢熶駭鑰
try{
Thread.sleep(100);
}catch(InterruptedExceptione){
}

Strings=null;

synchronized(this){
while(buf.size()==0){
System.out.println("闃熷垪涓虹┖錛屾秷璐硅:"+Thread.currentThread().getId()+"寮濮嬬瓑寰呫");
try{
this.wait();
}catch(InterruptedExceptione){
}
}

//鍙栧厛鏀懼叆鐨勫厓緔狅紝騫剁Щ闄
s=buf.get(0);
buf.remove(0);

//閫氱煡鐢熶駭鑰
this.notifyAll();
}

returns;
}

publicstaticvoidmain(String[]args){
//鑷宸卞疄鐜扮殑錛屽畨鍏ㄩ槦鍒
finalTestThread2tt=newTestThread2();

//鐢熶駭鑰
Threadp=newThread(newRunnable(){

@Override
publicvoidrun(){
while(!Thread.currentThread().isInterrupted()){
Randomr=newRandom();
tt.put(String.valueOf(r.nextInt(10)));
}
}

});

//娑堣垂鑰
Threadc1=newThread(newRunnable(){

@Override
publicvoidrun(){
while(!Thread.currentThread().isInterrupted()){
System.out.println("綰跨▼錛"+Thread.currentThread().getId()+"鑾峰彇鍒版暟鎹"+tt.take());
}
}

});

Threadc2=newThread(newRunnable(){

@Override
publicvoidrun(){
while(!Thread.currentThread().isInterrupted()){
System.out.println("綰跨▼錛"+Thread.currentThread().getId()+"鑾峰彇鍒版暟鎹"+tt.take());
}
}

});

p.start();
c1.start();
c2.start();

try{
p.join();
c1.join();
c2.join();
}catch(InterruptedExceptione){
}


}

}

⑶ 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();
}
}

}
}

⑷ 楂樺垎鎮璧廕ava紼嬪簭錛屾ワ紒錛侊紒

import java.awt.*;
import java.awt.event.*;
//淇勭綏鏂鏂瑰潡綾
public class ERS_Block extends Frame{
public static boolean isPlay=false;
public static int level=1,score=0;
public static TextField scoreField,levelField;

public static MyTimer timer;
GameCanvas gameScr;

public static void main(String[] argus){
ERS_Block ers = new ERS_Block("淇勭綏鏂鏂瑰潡娓告垙 V1.0 Author:Vincent");
WindowListener win_listener = new WinListener();
ers.addWindowListener(win_listener);
}

//淇勭綏鏂鏂瑰潡綾葷殑鏋勯犳柟娉
ERS_Block(String title){
super(title);

setSize(600,480);
setLayout(new GridLayout(1,2));

gameScr = new GameCanvas();
gameScr.addKeyListener(gameScr);

timer = new MyTimer(gameScr);
timer.setDaemon(true);
timer.start();
timer.suspend();

add(gameScr);

Panel rightScr = new Panel();
rightScr.setLayout(new GridLayout(2,1,0,30));
rightScr.setSize(120,500);
add(rightScr);

//鍙寵竟淇℃伅紿椾綋鐨勫竷灞
MyPanel infoScr = new MyPanel();
infoScr.setLayout(new GridLayout(4,1,0,5));
infoScr.setSize(120,300);
rightScr.add(infoScr);

//瀹氫箟鏍囩懼拰鍒濆嬪
Label scorep = new Label("鍒嗘暟:",Label.LEFT);
Label levelp = new Label("綰ф暟:",Label.LEFT);
Label namep = new Label("濮撳悕錛氬紶涓",Label.LEFT);
Label nump = new Label("瀛﹀彿:110821332",Label.LEFT);
scoreField = new TextField(8);
levelField = new TextField(8);
scoreField.setEditable(false);
levelField.setEditable(false);
infoScr.add(namep);
infoScr.add(nump);
infoScr.add(scorep);
infoScr.add(scoreField);
infoScr.add(levelp);
infoScr.add(levelField);
scorep.setSize(new Dimension(20,60));
scoreField.setSize(new Dimension(20,60));
levelp.setSize(new Dimension(20,60));
levelField.setSize(new Dimension(20,60));
scoreField.setText("0");
levelField.setText("1");

//鍙寵竟鎺у埗鎸夐挳紿椾綋鐨勫竷灞
MyPanel controlScr = new MyPanel();
controlScr.setLayout(new GridLayout(5,1,0,5));
rightScr.add(controlScr);

//瀹氫箟鎸夐挳play
Button play_b = new Button("寮濮嬫父鎴");
play_b.setSize(new Dimension(50,200));
play_b.addActionListener(new Command(Command.button_play,gameScr));

//瀹氫箟鎸夐挳Level UP
Button level_up_b = new Button("鎻愰珮綰ф暟");
level_up_b.setSize(new Dimension(50,200));
level_up_b.addActionListener(new Command(Command.button_levelup,gameScr));

//瀹氫箟鎸夐挳Level Down
Button level_down_b =new Button("闄嶄綆綰ф暟");
level_down_b.setSize(new Dimension(50,200));
level_down_b.addActionListener(new Command(Command.button_leveldown,gameScr));

//瀹氫箟鎸夐挳Level Pause
Button pause_b =new Button("娓告垙鏆傚仠");
pause_b.setSize(new Dimension(50,200));
pause_b.addActionListener(new Command(Command.button_pause,gameScr));

//瀹氫箟鎸夐挳Quit
Button quit_b = new Button("閫鍑烘父鎴");
quit_b.setSize(new Dimension(50,200));
quit_b.addActionListener(new Command(Command.button_quit,gameScr));

controlScr.add(play_b);
controlScr.add(level_up_b);
controlScr.add(level_down_b);
controlScr.add(pause_b);
controlScr.add(quit_b);
setVisible(true);
gameScr.requestFocus();
}
}

//閲嶅啓MyPanel綾伙紝浣縋anel鐨勫洓鍛ㄧ暀絀洪棿
class MyPanel extends Panel{
public Insets getInsets(){
return new Insets(30,50,30,50);
}
}

//娓告垙鐢誨竷綾
class GameCanvas extends Canvas implements KeyListener{
final int unitSize = 30; //灝忔柟鍧楄竟闀
int rowNum; //姝f柟鏍肩殑琛屾暟
int columnNum; //姝f柟鏍肩殑鍒楁暟
int maxAllowRowNum; //鍏佽告湁澶氬皯琛屾湭鍓
int blockInitRow; //鏂板嚭鐜板潡鐨勮搗濮嬭屽潗鏍
int blockInitCol; //鏂板嚭鐜板潡鐨勮搗濮嬪垪鍧愭爣
int [][] scrArr; //灞忓箷鏁扮粍
Block b; //瀵規柟蹇鐨勫紩鐢

//鐢誨竷綾葷殑鏋勯犳柟娉
GameCanvas(){
rowNum = 15;
columnNum = 10;
maxAllowRowNum = rowNum - 2;
b = new Block(this);
blockInitRow = rowNum - 1;
blockInitCol = columnNum/2 - 2;
scrArr = new int [32][32];
}

//鍒濆嬪寲灞忓箷錛屽苟灝嗗睆騫曟暟緇勬竻闆剁殑鏂規硶
void initScr(){
for(int i=0;i<rowNum;i++)
for (int j=0; j<columnNum;j++)
scrArr[i][j]=0;
b.reset();
repaint();
}

//閲嶆柊鍒鋒柊鐢誨竷鏂規硶
public void paint(Graphics g){
for(int i = 0; i < rowNum; i++)
for(int j = 0; j < columnNum; j++)
drawUnit(i,j,scrArr[i][j]);
}

//鐢繪柟鍧楃殑鏂規硶
public void drawUnit(int row,int col,int type){
scrArr[row][col] = type;
Graphics g = getGraphics();
switch(type){ //琛ㄧず鐢繪柟蹇鐨勬柟娉
case 0: g.setColor(Color.black);break; //浠ヨ儗鏅涓洪滆壊鐢
case 1: g.setColor(Color.blue);break; //鐢繪e湪涓嬭惤鐨勬柟鍧
case 2: g.setColor(Color.magenta);break; //鐢誨凡緇忚惤涓嬬殑鏂規硶
}
g.fill3DRect(col*unitSize,getSize().height-(row+1)*unitSize,unitSize,unitSize,true);
g.dispose();
}

public Block getBlock(){
return b; //榪斿洖block瀹炰緥鐨勫紩鐢
}

//榪斿洖灞忓箷鏁扮粍涓(row,col)浣嶇疆鐨勫睘鎬у
public int getScrArrXY(int row,int col){
if (row < 0 || row >= rowNum || col < 0 || col >= columnNum)
return(-1);
else
return(scrArr[row][col]);
}

//榪斿洖鏂板潡鐨勫垵濮嬭屽潗鏍囨柟娉
public int getInitRow(){
return(blockInitRow); //榪斿洖鏂板潡鐨勫垵濮嬭屽潗鏍
}

//榪斿洖鏂板潡鐨勫垵濮嬪垪鍧愭爣鏂規硶
public int getInitCol(){
return(blockInitCol); //榪斿洖鏂板潡鐨勫垵濮嬪垪鍧愭爣
}

//婊¤屽垹闄ゆ柟娉
void deleteFullLine(){
int full_line_num = 0;
int k = 0;
for (int i=0;i<rowNum;i++){
boolean isfull = true;

L1:for(int j=0;j<columnNum;j++)
if(scrArr[i][j] == 0){
k++;
isfull = false;
break L1;
}
if(isfull) full_line_num++;
if(k!=0 && k-1!=i && !isfull)
for(int j = 0; j < columnNum; j++){
if (scrArr[i][j] == 0)
drawUnit(k-1,j,0);
else
drawUnit(k-1,j,2);
scrArr[k-1][j] = scrArr[i][j];
}
}
for(int i = k-1 ;i < rowNum; i++){
for(int j = 0; j < columnNum; j++){
drawUnit(i,j,0);
scrArr[i][j]=0;
}
}
ERS_Block.score += full_line_num;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}

//鍒ゆ柇娓告垙鏄鍚︾粨鏉熸柟娉
boolean isGameEnd(){
for (int col = 0 ; col <columnNum; col ++){
if(scrArr[maxAllowRowNum][col] !=0)
return true;
}
return false;
}

public void keyTyped(KeyEvent e){
}

public void keyReleased(KeyEvent e){
}

//澶勭悊閿鐩樿緭鍏ョ殑鏂規硶
public void keyPressed(KeyEvent e){
if(!ERS_Block.isPlay)
return;
switch(e.getKeyCode()){
case KeyEvent.VK_DOWN:b.fallDown();break;
case KeyEvent.VK_LEFT:b.leftMove();break;
case KeyEvent.VK_RIGHT:b.rightMove();break;
case KeyEvent.VK_SPACE:b.leftTurn();break;
}
}
}

//澶勭悊鎺у埗綾
class Command implements ActionListener{
static final int button_play = 1; //緇欐寜閽鍒嗛厤緙栧彿
static final int button_levelup = 2;
static final int button_leveldown = 3;
static final int button_quit = 4;
static final int button_pause = 5;
static boolean pause_resume = true;

int curButton; //褰撳墠鎸夐挳
GameCanvas scr;

//鎺у埗鎸夐挳綾葷殑鏋勯犳柟娉
Command(int button,GameCanvas scr){
curButton = button;
this.scr=scr;
}

//鎸夐挳鎵ц屾柟娉
public void actionPerformed (ActionEvent e){
switch(curButton){
case button_play:if(!ERS_Block.isPlay){
scr.initScr();
ERS_Block.isPlay = true;
ERS_Block.score = 0;
ERS_Block.scoreField.setText("0");
ERS_Block.timer.resume();
}
scr.requestFocus();
break;
case button_levelup:if(ERS_Block.level < 10){
ERS_Block.level++;
ERS_Block.levelField.setText(""+ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}
scr.requestFocus();
break;
case button_leveldown:if(ERS_Block.level > 1){
ERS_Block.level--;
ERS_Block.levelField.setText(""+ERS_Block.level);
ERS_Block.score = 0;
ERS_Block.scoreField.setText(""+ERS_Block.score);
}
scr.requestFocus();
break;
case button_pause:if(pause_resume){
ERS_Block.timer.suspend();
pause_resume = false;
}else{
ERS_Block.timer.resume();
pause_resume = true;
}
scr.requestFocus();
break;
case button_quit:System.exit(0);
}
}
}

//鏂瑰潡綾
class Block {
static int[][] pattern = {
{0x0f00,0x4444,0x0f00,0x4444},//鐢ㄥ嶮鍏榪涜嚦琛ㄧず錛屾湰琛岃〃紺洪暱鏉″洓縐嶇姸鎬
{0x04e0,0x0464,0x00e4,0x04c4},
{0x4620,0x6c00,0x4620,0x6c00},
{0x2640,0xc600,0x2640,0xc600},
{0x6220,0x1700,0x2230,0x0740},
{0x6440,0x0e20,0x44c0,0x8e00},
{0x0660,0x0660,0x0660,0x0660}
};
int blockType; //鍧楃殑妯″紡鍙鳳紙0-6錛
int turnState; //鍧楃殑緲昏漿鐘舵侊紙0-3錛
int blockState; //蹇鐨勪笅钀界姸鎬
int row,col; //鍧楀湪鐢誨竷涓婄殑鍧愭爣
GameCanvas scr;

//鍧楃被鐨勬瀯閫犳柟娉
Block(GameCanvas scr){
this.scr = scr;
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
}

//閲嶆柊鍒濆嬪寲鍧楋紝騫舵樉紺烘柊鍧
public void reset(){
blockType = (int)(Math.random() * 1000)%7;
turnState = (int)(Math.random() * 1000)%4;
blockState = 1;
row = scr.getInitRow();
col = scr.getInitCol();
dispBlock(1);
}

//瀹炵幇鈥滃潡鈥濈炕杞鐨勬柟娉
public void leftTurn(){
if(assertValid(blockType,(turnState + 1)%4,row,col)){
dispBlock(0);
turnState = (turnState + 1)%4;
dispBlock(1);
}
}

//瀹炵幇鈥滃潡鈥濈殑宸︾Щ鐨勬柟娉
public void leftMove(){
if(assertValid(blockType,turnState,row,col-1)){
dispBlock(0);
col--;
dispBlock(1);
}
}

//瀹炵幇鍧楃殑鍙崇Щ
public void rightMove(){
if(assertValid(blockType,turnState,row,col+1)){
dispBlock(0);
col++;
dispBlock(1);
}
}

//瀹炵幇鍧楄惤涓嬬殑鎿嶄綔鐨勬柟娉
public boolean fallDown(){
if(blockState == 2)
return(false);
if(assertValid(blockType,turnState,row-1,col)){
dispBlock(0);
row--;
dispBlock(1);
return(true);
}else{
blockState = 2;
dispBlock(2);
return(false);
}
}

//鍒ゆ柇鏄鍚︽g『鐨勬柟娉
boolean assertValid(int t,int s,int row,int col){
int k = 0x8000;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if((int)(pattern[t][s]&k) != 0){
int temp = scr.getScrArrXY(row-i,col+j);
if (temp<0||temp==2)
return false;
}
k = k >> 1;
}
}
return true;
}

//鍚屾ユ樉紺虹殑鏂規硶
public synchronized void dispBlock(int s){
int k = 0x8000;
for (int i = 0; i < 4; i++){
for(int j = 0; j < 4; j++){
if(((int)pattern[blockType][turnState]&k) != 0){
scr.drawUnit(row-i,col+j,s);
}
k=k>>1;
}
}
}
}

//瀹氭椂綰跨▼
class MyTimer extends Thread{
GameCanvas scr;

public MyTimer(GameCanvas scr){
this.scr = scr;
}

public void run(){
while(true){
try{
sleep((10-ERS_Block.level + 1)*100);
}
catch(InterruptedException e){}
if(!scr.getBlock().fallDown()){
scr.deleteFullLine();
if(scr.isGameEnd()){
ERS_Block.isPlay = false;
suspend();
}else
scr.getBlock().reset();
}
}
}
}

class WinListener extends WindowAdapter{
public void windowClosing (WindowEvent l){
System.exit(0);
}
}

⑸ Java程序設計課程設計 學生信息管理系統 要求:使用圖形用戶界面用資料庫建立1或

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(); //創建一個對象 }

熱點內容
ps4各個伺服器有什麼區別 發布:2024-05-06 14:10:38 瀏覽:484
手機上怎麼玩韓國伺服器游戲 發布:2024-05-06 14:10:20 瀏覽:58
頻繁的解壓縮 發布:2024-05-06 14:09:30 瀏覽:820
怎麼在紅帽上裝c語言編譯器 發布:2024-05-06 13:58:38 瀏覽:507
linuxtomcat設置 發布:2024-05-06 13:50:11 瀏覽:28
c語言需要什麼基礎 發布:2024-05-06 13:46:10 瀏覽:687
python利器 發布:2024-05-06 13:33:56 瀏覽:731
ts代碼編譯成umd 發布:2024-05-06 13:13:38 瀏覽:724
糧庫存儲糧種類 發布:2024-05-06 13:11:26 瀏覽:52
一般網路的dns伺服器是什麼 發布:2024-05-06 13:02:43 瀏覽:153