import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JScrollPane;
public class Main {
static int max;
static TextArea ta;
static TextField tf;
static TextField tf1;
static int step = 0;
static int shape = 0;
static MyCanvas C[] = new MyCanvas[20];
static final Panel p21 = new Panel();
static final CardLayout c = new CardLayout(5, 5);
static int maxs=0;
static int now=0;
public static void main(String[] args) {
final Frame f = new Frame("火车车厢重排(队列)");
f.addWindowListener((new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}));
Panel main = new Panel();
main.setLayout(new BorderLayout(10, 5));
f.setLayout(new BorderLayout(10, 5));
f.setResizable(false);
// panel 1
Panel p1 = new Panel();
p1.setLayout(new BorderLayout(5, 15));
Panel p11 = new Panel();
p11.setLayout(new BorderLayout());
Label l1 = new Label("车厢序列:");
tf = new TextField(40);
ta = new TextArea(10, 40);
ta.setEditable(false);
p11.add(l1, BorderLayout.WEST);
p11.add(tf, BorderLayout.CENTER);
p1.add(p11, BorderLayout.NORTH);
p1.add(ta, BorderLayout.CENTER);
// panel 2
Panel p2 = new Panel();
p2.setPreferredSize(new Dimension(200, 400));
p2.setLayout(new BorderLayout(5, 15));
JScrollPane sp2 = new JScrollPane();
sp2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
sp2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
for (int i = 0; i < 20; i++) {
Main.C[i] = new MyCanvas();
}
p21.setLayout(c);
p21.setPreferredSize(new Dimension(200, 400));
Panel p22 = new Panel();
p22.setLayout(new BorderLayout());
Label l2 = new Label("缓冲轨数:");
tf1 = new TextField(20);
p22.add(l2, BorderLayout.WEST);
p22.add(tf1, BorderLayout.CENTER);
sp2.setViewportView(p21);
p2.add(p22, BorderLayout.NORTH);
p2.add(sp2, BorderLayout.CENTER);
// panel 3
Panel p3 = new Panel();
p3.setLayout(new GridLayout(1, 6));
Button b0 = new Button("开始排序");
Button b1 = new Button("下一步");
Button b2 = new Button("上一步");
Button b3 = new Button("重新开始");
Button b4 = new Button("退出");
b0.addActionListener(new b0Listener());
b1.addActionListener(new b1Listener());
b2.addActionListener(new b2Listener() );
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ta.setText(null);
tf.setText(null);
tf1.setText(null);
step = 0;
shape = 0;
p21.removeAll();
}
});
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
p3.add(b0);
p3.add(b2);
p3.add(b1);
p3.add(b3);
p3.add(b4);
main.add(p1, BorderLayout.WEST);
main.add(p2, BorderLayout.CENTER);
main.add(p3, BorderLayout.SOUTH);
Main.ta.setText("请输入火车车厢序列,车厢号在1~9之间,中间用英文,隔开\n请输入缓冲轨数量,数量在0~9之间");
f.add(main, BorderLayout.CENTER);
f.add(new Panel(), BorderLayout.NORTH);
f.add(new Panel(), BorderLayout.EAST);
f.add(new Panel(), BorderLayout.WEST);
f.add(new Panel(), BorderLayout.SOUTH);
f.setBounds(50, 50, 800, 500);
// f.pack();
f.setVisible(true);
}
}