package USC.Dialog;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.sql.SQLException;
import javax.swing.*;
import USC.Util.FrameJdbc;
import USC.Util.ImageLoad;
import USC.Util.JDBC;
public class TicketBuyDialog extends JDialog{
Image i_up;
JButton jb_buy=new JButton("购买");
JButton jb_update=new JButton("刷新");
String Tid;
String Yseat,Rseat,Ybed,Rbed,Sticket;
Font f1,f2;
int x,y;
MyPanel mp;
public TicketBuyDialog(Dialog dialog,boolean model,String Tid,int x,int y) throws Exception{
super(dialog, model);
this.Tid=Tid;
setLayout(null);
i_up=ImageLoad.ImageLoad("Image\\DialogImage\\Tickbuy.png");
f1=new Font("宋体", Font.BOLD, 25);
f2=new Font("宋体", Font.PLAIN, 15);
addComponent();
setTicketNumber();
setBounds(x, y, i_up.getWidth(null), 400);
setResizable(false);
setVisible(true);
}
public void init(String Tid){
this.Tid=Tid;
mp.repaint();
}
private void addComponent(){
mp=new MyPanel();
add(mp);
}
public void update(){
jb_update.doClick();
}
public void init(){
mp.init();
}
class MyPanel extends JPanel{
JTextField jtf1,jtf2,jtf3,jtf4,jtf5;
boolean canbuy=true;
Color back=new Color(255, 217, 217);
public void init(){
jtf1.setText("0");jtf2.setText("0");jtf3.setText("0");jtf4.setText("0");
jtf5.setText("0");
}
public MyPanel(){
super();
this.setLayout(null);
this.setBounds(0, 0, i_up.getWidth(null), 380);
jtf1=new JTextField("0");jtf2=new JTextField("0");jtf3=new JTextField("0");
jtf4=new JTextField("0");jtf5=new JTextField("0");
jtf1.setForeground(Color.LIGHT_GRAY);
jtf2.setForeground(Color.LIGHT_GRAY);
jtf3.setForeground(Color.LIGHT_GRAY);
jtf4.setForeground(Color.LIGHT_GRAY);
jtf5.setForeground(Color.LIGHT_GRAY);
jtf1.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if(jtf1.getText().trim().isEmpty()){
jtf1.setText("0");
}
jtf1.setForeground(Color.LIGHT_GRAY);
if(Integer.valueOf(jtf1.getText().trim())<0){
canbuy=false;
JOptionPane.showMessageDialog(null, "您输入的数量有误", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf1.setText("0");
return;
}
if(Yseat.equals("无")&&!jtf1.getText().trim().equals("0")){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起票已卖完", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf1.setText("0");
return;
}
if(Yseat.equals("无"))Yseat="0";
if(Integer.valueOf(Yseat)<Integer.valueOf(jtf1.getText().trim())){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起没有足够车票", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf1.setText("0");
return;
}
canbuy=true;
}
public void focusGained(FocusEvent arg0) {
jtf1.setForeground(Color.BLACK);
jtf1.selectAll();
}
});
jtf2.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if(jtf2.getText().trim().isEmpty()){
jtf2.setText("0");
}
jtf2.setForeground(Color.LIGHT_GRAY);
if(Integer.valueOf(jtf2.getText().trim())<0){
canbuy=false;
JOptionPane.showMessageDialog(null, "您输入的数量有误", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf2.setText("0");
return;
}
if(Rseat.equals("无")&&!jtf2.getText().trim().equals("0")){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起票已卖完", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf2.setText("0");
return;
}
if(Rseat.equals("无"))Rseat="0";
if(Integer.valueOf(Rseat)<Integer.valueOf(jtf2.getText().trim())){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起没有足够车票", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf2.setText("0");
return;
}
canbuy=true;
}
public void focusGained(FocusEvent arg0) {
jtf2.setForeground(Color.BLACK);
jtf2.selectAll();
}
});
jtf3.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if(jtf3.getText().trim().isEmpty()){
jtf3.setText("0");
}
jtf3.setForeground(Color.LIGHT_GRAY);
if(Integer.valueOf(jtf3.getText().trim())<0){
canbuy=false;
JOptionPane.showMessageDialog(null, "您输入的数量有误", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf3.setText("0");
return;
}
if(Ybed.equals("无")&&!jtf3.getText().trim().equals("0")){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起票已卖完", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf3.setText("0");
return;
}
if(Ybed.equals("无"))Ybed="0";
if(Integer.valueOf(Ybed)<Integer.valueOf(jtf3.getText().trim())){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起没有足够车票", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf3.setText("0");
return;
}
canbuy=true;
}
public void focusGained(FocusEvent arg0) {
jtf3.setForeground(Color.BLACK);
jtf3.selectAll();
}
});
jtf4.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if(jtf4.getText().trim().isEmpty()){
jtf4.setText("0");
}
jtf4.setForeground(Color.LIGHT_GRAY);
if(Integer.valueOf(jtf4.getText().trim())<0){
canbuy=false;
JOptionPane.showMessageDialog(null, "您输入的数量有误", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf4.setText("0");
return;
}
if(Rbed.equals("无")&&!jtf4.getText().trim().equals("0")){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起票已卖完", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf4.setText("0");
return;
}
if(Rbed.equals("无"))Rbed="0";
if(Integer.valueOf(Rbed)<Integer.valueOf(jtf4.getText().trim())){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起没有足够车票", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf4.setText("0");
return;
}
canbuy=true;
}
public void focusGained(FocusEvent arg0) {
jtf4.setForeground(Color.BLACK);
jtf4.selectAll();
}
});
jtf5.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if(jtf5.getText().trim().isEmpty()){
jtf5.setText("0");
}
jtf5.setForeground(Color.LIGHT_GRAY);
if(Integer.valueOf(jtf5.getText().trim())<0){
canbuy=false;
JOptionPane.showMessageDialog(null, "您输入的数量有误", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf5.setText("0");
return;
}
if(Sticket.equals("无")&&!jtf5.getText().trim().equals("0")){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起票已卖完", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf5.setText("0");
return;
}
if(Sticket.equals("无"))Sticket="0";
if(Integer.valueOf(Sticket)<Integer.valueOf(jtf5.getText().trim())){
canbuy=false;
JOptionPane.showMessageDialog(null, "对不起没有足够车票", "提示", JOptionPane.INFORMATION_MESSAGE);
jtf5.setText("0");
return;
}
canbuy=true;
}
public void focusGained(FocusEvent arg0) {
jtf5.setForeground(Color.BLACK);
jtf5.selectAll();
}
});
this.addComponent();
this.addActionlistener();
}
private void addComponent(){
jtf1.setBounds(290, 110, 50, 20);
jtf2.setBounds(290, 135, 50, 20);
jtf3.setBounds(290, 165, 50, 20);
jtf4.setBounds(290, 195, 50, 20);
jtf5.setBounds(290, 225, 50, 20);
jb_buy.setBounds(320, 300, 80, 25);
jb_update.setBounds(220, 300, 80, 25);
this.add(jb_buy);this.add(jb_update);
this.add(jtf1);this.a
- 1
- 2
- 3
前往页