当前位置:首页 » 编程语言 » 大二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(); //创建一个对象 }

热点内容
电信路由器密码设置无线路由器怎么设置密码 发布:2024-05-18 10:55:00 浏览:647
安卓系统是属于哪个国家的手机 发布:2024-05-18 10:41:41 浏览:99
linux运维前景 发布:2024-05-18 10:24:44 浏览:658
c语言crc算法 发布:2024-05-18 09:59:03 浏览:644
linuxc编程视频 发布:2024-05-18 09:55:58 浏览:273
如何建造一个好的服务器 发布:2024-05-18 09:54:30 浏览:524
编译原理中的左结合 发布:2024-05-18 09:42:00 浏览:26
怎样加密路由器 发布:2024-05-18 09:41:55 浏览:605
百度云不能上传视频了 发布:2024-05-18 09:41:08 浏览:148
mac适合买大存储 发布:2024-05-18 08:30:08 浏览:583