Swing开发抽奖系统
一个简易的抽奖系统
数据库部分采用上一次的工具类 JDBC工具类
直奔主题,上源码
package Lucky;
import java.awt.Font;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Myframe extends JFrame {
JPanel panel = new JPanel();
JLabel label = new JLabel("欢迎进入抽奖系统");
JButton button1 = new JButton("1.进行抽奖");
JButton button2 = new JButton("2.退出系统");
JButton button3 = new JButton("3.查询纪录");
JButton button4 = new JButton("4.统计分析");
public Myframe(String title) {
super(title);
this.setSize(270, 400);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
this.setContentPane(panel);
label.setFont(new Font("黑体", Font.BOLD, 20));
this.add(label);
button1.addActionListener(e -> {
try {
new Welcome().LuckyDraw();
} catch (SQLException e1) {
e1.printStackTrace();
System.out.println("抽奖失败");
}
});
button2.addActionListener(e -> {
int select = JOptionPane.showConfirmDialog(this, "是否确认退出", "确认", JOptionPane.YES_NO_OPTION);
if (0 == select) {
System.out.println("退出");
this.setVisible(false);
this.dispose();
}
});
button3.addActionListener(e -> {
System.out.println("抽奖纪录:");
try {
SelectUtil.SelectMethod();
} catch (SQLException e1) {
e1.printStackTrace();
}
});
button4.addActionListener(e -> {
new Welcome().total();
});
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
}
public static void main(String[] args) {
JFrame welcomeframe = new Myframe("抽奖系统");
}
}
界面效果:
运行效果:
1.按钮一 抽奖:
2.按钮三 查询:
3.按钮四 统计:
4.按钮二 退出: