这个问题与前一个问题有关。这几乎是同一个程序。我想打印出所选座位的座位号,但我无法弄清楚如何。如果我能得到所选座位的行号和列号,我可以打印出座位号。可以有人帮我吗?
import javax.swing.*;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import javax.swing.border.LineBorder;
import javax.swing.border.Border;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import java.io.File;
class silver1 extends JFrame implements ActionListener {
private JButton[] bt = new JButton[1];
JFrame fr=new JFrame();
static int c=250;
static int j1=1;
static int c11=680;
static int k=105;
static int k11=295;
static int sum=0;
static int s;
static int j;
public silver1() throws IOException{
JLabel l1=new JLabel();
JLabel l2=new JLabel();
JLabel l3=new JLabel();
JLabel l4=new JLabel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
l1.setText("<html><font size=7><font color=white>Select Your Seats</html>");
l2.setText("<html><font size=5><font color=white>All Eyes This Way Please!!</html>");
l3.setText("<html><font size=5><font color=white>GOLD</html>");
l4.setText("<html><font size=5><font color=white>SILVER</html>");
p2.setBackground(Color.gray);
p3.setBackground(Color.gray);
p4.setBackground(Color.gray);
p1.setBackground(Color.BLUE);
fr.add(l2);
fr.add(p2);
fr.add(l1);
fr.add(p1);
fr.add(l3);
fr.add(p3);
fr.add(l4);
fr.add(p4);
l1.setBounds(450,15,590,40);
p1.setBounds(1,1,3400,75);
p2.setBounds(300,605,650,35);
l2.setBounds(500,605,650,35);
l3.setBounds(636,80,80,25);
p3.setBounds(636,80,55,25);
p4.setBounds(625,265,70,25);
l4.setBounds(625,265,80,25);
fr.setLayout(null);
for(s=1;s<=4;s++,k+=40)
{
c=250;c11=680;
for(j=1;j<=10;j++,c+=40)
{
for (int i = 0; i < bt.length; i++,j1++) {
JLabel lab=new JLabel();
bt[i] = new JButton(Integer.toString(j1));
bt[i].setHorizontalTextPosition(AbstractButton.CENTER);
bt[i].setVerticalTextPosition(AbstractButton.CENTER);
fr.add(bt[i]);
Border noBorder = new LineBorder(Color.WHITE, 0);
bt[i].setBorder(noBorder);
bt[i].setBackground(Color.WHITE);
//bt[i].addActionListener(this);
bt[i].setBounds(c,k,40,40);
}
}
for(j=1;j<=10;j++,c11+=40)
{
for (int i = 0; i < bt.length; i++,j1++) {
bt[i] = new JButton(Integer.toString(j1));
bt[i].setHorizontalTextPosition(AbstractButton.CENTER);
bt[i].setVerticalTextPosition(AbstractButton.CENTER);
fr.add(bt[i]);
Border noBorder = new LineBorder(Color.WHITE, 0);
bt[i].setBorder(noBorder);
bt[i].setBackground(Color.WHITE);
//bt[i].addActionListener(this);
bt[i].setBounds(c11,k,40,40);
}
}
}
for(s=1;s<=7;s++,k11+=40)
{
c=250;c11=680;
for(j=1;j<=10;j++,c+=40)
{
for (int i = 0; i < bt.length; i++,j1++) {
JLabel lab=new JLabel();
bt[i] = new JButton(Integer.toString(j1));
bt[i].setHorizontalTextPosition(AbstractButton.CENTER);
bt[i].setVerticalTextPosition(AbstractButton.CENTER);
fr.add(bt[i]);
Border noBorder = new LineBorder(Color.WHITE, 0);
bt[i].setBorder(noBorder);
bt[i].setBackground(Color.WHITE);
bt[i].addActionListener(this);
bt[i].setBounds(c,k11,40,40);
}
}
for(j=1;j<=10;j++,c11+=40)
{
for (int i = 0; i < bt.length; i++,j1++) {
bt[i] = new JButton(Integer.toString(j1));
bt[i].setHorizontalTextPosition(AbstractButton.CENTER);
bt[i].setVerticalTextPosition(AbstractButton.CENTER);
fr.add(bt[i]);
Border noBorder = new LineBorder(Color.WHITE, 0);
bt[i].setBorder(noBorder);
bt[i].setBackground(Color.WHITE);
bt[i].addActionListener(this);
bt[i].setBounds(c11,k11,40,40);
}
}
}
int k1=105;
char a='A';
for(int s1=1;s1<=12;s1++,k1+=40,a++)
{
if(a=='E')
{k1-=10;
continue; }
JLabel label=new JLabel();
label.setText(a+"");
fr.add(label);
label.setBounds(220,k1,40,40);
}
JButton b1=new JButton("<html><font size=5><font color=white>BACK </html>");
b1.addActionListener(new Action());
b1.setBackground(Color.RED);
fr.add(b1);
b1.setBounds(4,82,90,30);
fr.setVisible(true);
fr.pack();
fr.setSize(new Dimension(3400,765));
c=250;
c11=680;
k=105;
k11=295;
}
public void actionPerformed(ActionEvent e) {
JButton pressedButton = (JButton)e.getSource();
if(pressedButton.getBackground() == Color.GREEN){
if(sum != 0)
{
JLabel l=new JLabel();
JPanel p=new JPanel();
pressedButton.setBackground(Color.WHITE);
sum--;
l.setText("<html><font size=7><font color= white>Number of Seats Selected: "+sum+"");
p.add(l);
p.setBackground(Color.BLUE);
fr.add(p);
l.setBounds(390,15,590,40);
p.setBounds(1,1,3400,75);
}
else
{
JLabel l=new JLabel();
pressedButton.setBackground(Color.WHITE);
sum--;
l.setText("<html><font size=5>Select Your Seats"+"");
fr.add(l);
l.setBounds(390,25,290,75);
}
}else if(pressedButton.getBackground() == Color.WHITE){
JLabel l=new JLabel();
JPanel p=new JPanel();
pressedButton.setBackground(Color.GREEN);
sum++;
l.setText("<html><font size=7><font color= white>Number of Seats Selected: "+sum+"");
p.add(l);
p.setBackground(Color.BLUE);
fr.add(p);
l.setBounds(390,15,590,40);
p.setBounds(1,1,3400,75);
}else{
pressedButton.setBackground(Color.WHITE);
}
if(sum>-1)
{
JButton b1=new JButton("<html><font size=5><font
color=white>BOOK</html>");
b1.addActionListener(new Actionn());
b1.setBackground(Color.BLUE);
fr.add(b1);
b1.setBounds(4,132,90,30);
if(sum==0)
fr.remove(b1);
}
}
class Action implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
class Actionn implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
}
}
}
public class silver {
public static void main() throws IOException
{
silver1 bcts = new silver1();
}
}