日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基于myecilpse软件制作的欢乐摇奖器

發布時間:2024/3/24 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于myecilpse软件制作的欢乐摇奖器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

源代碼:

1.創建窗體的代碼:

package?lottery;

import?java.awt.Color;

import?java.awt.Font;

import?javax.swing.JFrame;

import?javax.swing.JTextArea;

public?class?LotteryFrame {

public?static?void?main(String[] args) {

JFrame frame=new?JFrame();

frame.setSize(868, 552);

frame.setLocationRelativeTo(null);

????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

????frame.setUndecorated(true);

????frame.setLayout(null);

????Lotterypanel panel=new?Lotterypanel();

????panel.setBounds(0, 0, 868, 552);

????frame.add(panel);

????frame.setVisible(true);

????panel.addMouseListener(panel);

}

}

package?lottery;

import?java.awt.Color;

import?java.awt.Font;

import?javax.swing.JFrame;

import?javax.swing.JTextArea;

public?class?LotteryFrame {

public?static?void?main(String[] args) {

JFrame frame=new?JFrame();

frame.setSize(868, 552);

frame.setLocationRelativeTo(null);

????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

????frame.setUndecorated(true);

????frame.setLayout(null);

????Lotterypanel panel=new?Lotterypanel();

????panel.setBounds(0, 0, 868, 552);

????frame.add(panel);

????frame.setVisible(true);

????panel.addMouseListener(panel);

????}

}

2.創建面板的代碼:

package?lottery;

import?java.awt.Color;

import?java.awt.Font;

import?java.awt.Graphics;

import?java.awt.event.MouseEvent;

import?java.awt.event.MouseListener;

import?java.io.BufferedReader;

import?java.io.FileInputStream;

import?java.io.FileNotFoundException;

import?java.io.InputStreamReader;

import?java.util.ArrayList;

import?javax.swing.ImageIcon;

import?javax.swing.JPanel;

public?class?Lotterypanel?extends?JPanel implements?MouseListener,Runnable{

//定義初始量

String name="李菲菲";

String phone="13978673456";

boolean?isStart=true;

int?count=0;

int?y=222;

int?n=0;

int?id=0;

boolean?isMove=false;

//定義集合

ArrayList<String>data=new?ArrayList<String>();

ArrayList<String>result=new?ArrayList<String>();

private?int?i;

//讀取txt文件

public?Lotterypanel(){

read();

//創建線程

new?Thread(this).start();

}

public?void?read(){

try?{

BufferedReader br=new?BufferedReader(new?InputStreamReader(new?FileInputStream("src/lottery/lottery.txt")));

String str="";

while((str=br.readLine())!=null){

data.add(str);

count++;

id++;

????????????}

} catch?(Exception e) {

// TODO?Auto-generated catch block

e.printStackTrace();

}

}

public?void?paint(Graphics g){

super.paint(g);

//讀寫圖片

????g.drawImage(new?ImageIcon("img/case05/back2.jpg").getImage(), 0, 0,null);

????g.drawImage(new?ImageIcon("img/case05/close.png").getImage(), 840, 12,null);

????g.drawImage(new?ImageIcon("img/case05/again.png").getImage(), 645, 426,null);

????//改變字體顏色,大小和在面板上寫入數字

????g.setColor(Color.yellow);

Font font = new?Font("", Font.BOLD, 20);

g.setFont(font);

g.drawString("班級 姓名", 50, 520);

//控制開始和暫停按鈕

????if(isStart){

???? ?????g.drawImage(new?ImageIcon("img/case05/start.png").getImage(), 204, 311, null);

???? ?????g.drawImage(new?ImageIcon("img/case05/icon.jpg").getImage(), 620, 180,null);

???? }else{

???? ?g.drawImage(new?ImageIcon("img/case05/zanting1.png").getImage(), 204, 311, null);

???? }

????????????g.setColor(Color.black);

????????????g.setFont(new?Font("",Font.BOLD,30));

????????????g.drawString(name, 90, y);

????????????g.drawString(phone,283,y);

????????????g.drawString(count+"",310,410);

????????????g.setColor(Color.blue);

????????????g.setFont(new?Font("",Font.BOLD,20));

????????????for(i=0;i<result.size();i++){

???? ????g.drawString(result.get(i), 580, 130+i*22);

}

?????}

@Override

public?void?mouseClicked(MouseEvent e) {

// TODO?Auto-generated method stub

int?x=e.getX();

int?y=e.getY();

if(x>840&&x<840+17&&y>12&&y<12+18){

System.exit(0);

}else?if(x>204&&x<204+200&&y>311&&y<311+55){

if?(count==0){

return;

}else{

if(isStart){

isStart=false;

isMove=true;

}else{

isStart=true;

isMove=false;

String str=data.get(n%id);

result.add(str);

data.remove(n%id);

count--;

id--;

repaint();

}

}

}else?if(x>645&&x<645+116&&y>426&&y<426+42){

//清空和恢復原始數據

result.clear();

data.clear();

n=0;

id=0;

count=0;

read();

repaint();

}

}

@Override

public?void?mouseEntered(MouseEvent e) {

// TODO?Auto-generated method stub

}

@Override

public?void?mouseExited(MouseEvent e) {

// TODO?Auto-generated method stub

}

@Override

public?void?mousePressed(MouseEvent e) {

// TODO?Auto-generated method stub

}

@Override

public?void?mouseReleased(MouseEvent e) {

// TODO?Auto-generated method stub

}

@Override

//控制字符串跳動速度

public?void?run() {

// TODO?Auto-generated method stub

while(true){

if(isMove){

String[] str=data.get(n%id).split(":");

name=str[0];

phone=str[1];

?

while(y<222+23){

y=y+5;

repaint();

try?{

Thread.sleep(30);

} catch?(InterruptedException e) {

// TODO?Auto-generated catch block

e.printStackTrace();

}

}

y=222;

n++;

repaint();

???}

}

}

}

?

轉載于:https://www.cnblogs.com/msyou/p/5855265.html

總結

以上是生活随笔為你收集整理的基于myecilpse软件制作的欢乐摇奖器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。