‍
import javaawtColor;//界面不是很高大上档次,但是能满足你的基本需求,希望对你有用import javaawtFont;
import javaawtGridLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaxswingJButton;
import javaxswingJFrame;
import javaxswingJOptionPane;
import javaxswingborderBorder;
import javaxswingborderLineBorder;
public class 抽奖游戏 extends JFrame {
static 抽奖游戏 frame;
public 抽奖游戏() {
setLayout(new GridLayout(3, 3, 3, 3));
Border border = new LineBorder(ColorBLUE, 4);
JButton l1 = new JButton();
JButton l2 = new JButton();
JButton l3 = new JButton();
JButton l4 = new JButton();
JButton l5 = new JButton();
JButton l6 = new JButton();
JButton l7 = new JButton("祝你好运");
JButton l8 = new JButton("中奖规则");
JButton l9 = new JButton("再次抽奖");
l1setBorder(border);
l2setBorder(border);
l3setBorder(border);
l4setBorder(border);
l5setBorder(border);
l6setBorder(border);
l7setBorder(border);
l8setBorder(border);
l9setBorder(border);
String[] num2 = { "1", "2", "3", "4", "5", "6" };
l8addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
JOptionPaneshowMessageDialog(null, "游戏规则:\n" + "特等奖:\n"
+ "第一行或者第二行出现的数字全部相同\n"
+ "第一第二行出现升序的1,2,3,4,5,6或者降序的6,5,4,3,2,1\n" + "一等奖\n"
+ "1:第一行或第二行的数字降序排列或者升序排列\n"
+ "2:第一行或者第二行相邻的按钮出现一样的数字\n");
}
});
l9addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
l1setText("");
l2setText("");
l3setText("");
l4setText("");
l5setText("");
l6setText("");
l7setBackground(ColorlightGray);
l7setText("离中奖不远了!");
}
});
l6addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
l5addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
l4addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
l3addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
l2addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
l1addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
int j1 = (int) (Mathrandom() 10) % 6;
l1setText(num2[j1]);
int j2 = (int) (Mathrandom() 10) % 6;
l2setText(num2[j2]);
int j3 = (int) (Mathrandom() 10) % 6;
l3setText(num2[j3]);
int j4 = (int) (Mathrandom() 10) % 6;
l4setText(num2[j4]);
int j5 = (int) (Mathrandom() 10) % 6;
l5setText(num2[j5]);
int j6 = (int) (Mathrandom() 10) % 6;
l6setText(num2[j6]);
if (j1 == j2 && j2 == j3 || j4 == j5 && j5 == j6 || j1 == 1
&& j2 == 2 && j3 == 3 && j4 == 4 && j5 == 5 && j6 == 6
|| j1 == 6 && j2 == 5 && j3 == 4 && j4 == 3 && j5 == 2
&& j6 == 1) {
l7setBackground(Colorred);
l7setText("特等奖");
} else if (j1 > j2 && j2 > j3 || j3 > j2 && j2 > j1 || j4 > j5
&& j5 > j6 || j6 > j5 && j5 > j4 || j1 == j2
&& j5 == j4 || j1 == j2 && j5 == j6 || j3 == j2
&& j4 == j5 || j5 == j6 && j2 == j3) {
l7setBackground(ColorYELLOW);
l7setText("一等奖");
} else {
l7setBackground(ColorlightGray);
l7setText("未中奖,加油!");
}
}
});
Font font = new Font("", FontBOLD, 20);
l1setFont(font);
l2setFont(font);
l3setFont(font);
l4setFont(font);
l5setFont(font);
l6setFont(font);
l7setFont(font);
l8setFont(font);
l9setFont(font);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame = new 抽奖游戏();
framesetTitle("抽奖大战");
framesetSize(500, 500);
framesetLocationRelativeTo(null);
framesetVisible(true);
framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
}
上面的文本框‘下拉框你可以放到一个Jpanel里面去,假设jpanelA
中间的文本框和复选框你可以放到一个Jpanel里面去,假设jpanelB
下面的一个表格你放到一个Jpanel里面去,假设JpanelC
最终的结果如下:
做一个Jpanel为BorderLayOut的,取名japnelD,North为jpanelB,center为JpanelC
JSplitPane jsp=new JSplitPane(JSplitPaneVERTICAL_SPLIT,jpanelA,jpanelD);
最终结果就是这个jsp,你要是需要的话,发mail给我:wuzhuge1990@163com,我给你写好
其实你不用添加jlabel,直接方jpanel就可以
你可以重写 jpanel里面的 paintComponent()方法
public void paintComponent(Graphics g){superpaintComponent(g);
Graphics2D gr = (Graphics2D) g;
grdrawImage(img, x, y, width, height); //x ,y 是坐标
//想显示在上一张上面时
grdrawImage(img1, x, y, width, height); //只要保证这张比上一张小就行,大了就覆盖了
至于颜色,最简单的就是
grsetPaint(new color(0,0,0,05f))//前面三个就是RGB的数值,最后一个是透明度的数值
//想要上面显示文字?
grdrawString(str, x, y);//str就是字符串 x ,y 坐标
//当然 前提你可能会选择字体颜色和大小
grsetColor(ColorRED);
grsetFont(new Font("Arial Black",FontITALIC, 50));
//当然还有一种透明,可以设置透明 要在它后面执行
AlphaComposite newComposite = AlphaCompositegetInstance(
AlphaCompositeSRC_OVER, 05f);//在这里设置透明度
grsetComposite(newComposite);
有些地方是我手敲的 你自己注意大小写
}
swing的意思:
v(使)摆动,摇摆,摇荡;纵身跃向;荡向;悬吊到;(使)弧线运动,转弯,转动。
n摆动;挥动;转动;强劲节奏;改变;改变的程度;秋千。
1、读音:英 [swɪŋ],美 [swɪŋ]。
2、固定搭配:
The Swing 秋千 ; 裁缝 ; 摇摆乐 ; 全挥杆教学。
Swing Shift 小迷糊的情泪 ; 小夜班 ; 中班 ; 小迷糊情泪。
Full swing 如火如荼 ; 高挥杆 ; 全力挥拍 ; 达到活动的高潮。
Swing Copters 摇摆直升机 ; 摇摇欲坠 ; 晃飞机 ; 旋转直升机。
3、例句:
I like to swing
我喜欢荡秋千。
扩展资料
swing的过去式:swung,词汇解释如下:
1、释义:
v(使)摆动,摇摆,摇荡;纵身跃向;荡向;悬吊到;(使)弧线运动,转弯,转动。
2、读音:英 [swʌŋ],美 [swʌŋ]。
3、例句:
The door swung open again, spilling light into the cell
门再次打开了,光照亮了小屋。
import javaawt;
import javaxswing;
public class GUI extends JFrame{
private JMenuBar mb=new JMenuBar();
private JMenu mm=new JMenu("文件");
private JMenuItem mi1=new JMenuItem("粘贴");
private JMenuItem mi2=new JMenuItem("复制");
private JLabel l=new JLabel();
public GUI(){
thissetLayout(null);
mmadd(mi1);
mmadd(mi2);
mbadd(mm);
thissetJMenuBar(mb);
lsetText("我的第一个图形用户界面");
lsetBounds(10,10,450,30);
thisgetContentPane()add(l);
thissetBounds(330,250,500,150);
thissetVisible(true);
thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
}
public static void main(String[] args){
new GUI();
}
}
简单的说,每次启动进程a,进程a调用程序b,程序b是你的swing程序。
然后在程序a中设置升级的检查(就是联网,访问webservice),如果有新版,就下载文件,更新程序b,然后再调用。
注意
a,b应该是两个进程,至少也是两个classloader,如果你搞不定的话,可以在a升级后,退出。提示用户再次运行。
以上就是关于用swing编写一个java抽奖的程序,至少有5个按钮,显得高大上一点。全部的内容,包括:用swing编写一个java抽奖的程序,至少有5个按钮,显得高大上一点。、想开发一个如图的桌面应用程序,用javax.swing写,请问布局什么的,该怎么弄、在用Java的Swing开发程序时,我使用了很多个JLabel来铺满整个界面以实现图片的显示,但现等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)