?? trian2.java
字號:
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.*;
import java.io.*;
class Frame1 extends JFrame implements ActionListener,ItemListener
{
string c1="checi.dat";
string c2="車次查詢";
JFrame f=null;
JTextField tf1,tf2,tf3;
JDialog doalog;
JDialog dialog;
JScrollBar sbr;
public Frame1()
{
f=new JFrame("黑龍江省火車查詢");
Container cp=f.getContentPane();
JLabel label1=new JLabel("黑龍江省火車查詢",JLabel.CENTER);
label1.setFont(new Font("宋體",Font.BOLD,25));
label1.setForeground(Color.red);
JPanel pa=new JPanel(new GridLayout(3,1));
pa.add(label1);
JButton jButton1 = new JButton("歡迎進入");
jButton1.setFont(new Font("宋體",Font.BOLD,15));
jButton1.setForeground(Color.red);
jButton1.addActionListener(this);
pa.add(jButton1);
JButton jButton2 = new JButton("返回");
jButton2.setFont(new Font("宋體",Font.BOLD,15));
jButton2.setForeground(Color.red);
jButton2.addActionListener(this);
pa.add(jButton2);
cp.add(pa,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
f.addWindowListener(new WinLis());
f.setSize(250,250);
f.setResizable(false);
}
public void dial()
{
doalog=new JDialog(f,"歡迎進入",true);
Container diacp=doalog.getContentPane();
diacp.setLayout(new FlowLayout());
JCheckBox cb1,cb2;
cb1=new JCheckBox("車次查詢",false);
cb2=new JCheckBox("出發(fā)站--目的站查詢",false);
cb1.setFont(new Font("宋體",Font.BOLD,12));
cb1.setForeground(Color.red);
cb2.setFont(new Font("宋體",Font.BOLD,12));
cb2.setForeground(Color.red);
cb1.addItemListener(this);
cb2.addItemListener(this);
JLabel jLabel1 = new JLabel("歡迎使用黑龍江省火車查系統(tǒng)",JLabel.CENTER);
jLabel1.setFont(new Font("宋體",Font.BOLD,20));
jLabel1.setForeground(Color.red);
JLabel jLabel4= new JLabel("到",JLabel.CENTER);
jLabel4.setFont(new Font("宋體",Font.BOLD,12));
jLabel4.setForeground(Color.red);
tf1=new JTextField(20);
tf2=new JTextField(12);
tf3=new JTextField(12);
JPanel pal,pal1,pal2;
pal=new JPanel(new GridLayout(4,1));
pal.add(jLabel1);
pal1=new JPanel(new GridLayout(1,3));
pal1.add(cb1);
pal1.add(tf1);
pal.add(pal1);
pal2=new JPanel(new GridLayout(1,4));
pal2.add(cb2);
pal2.add(tf2);
pal2.add(jLabel4);
pal2.add(tf3);
pal.add(pal2);
JButton tbu1=new JButton("查詢");
tbu1.setFont(new Font("宋體",Font.BOLD,25));
tbu1.setForeground(Color.red);
tbu1.addActionListener(this);
pal.add(tbu1);
diacp.add(pal);
doalog.setBounds(100,100,650,300);
doalog.setResizable(false);
doalog.show();
}
getContenPane().add(jCheckbox);
cb1.addActionListener(new ActionListener(){
p
public void dial1()
{ dialog=new JDialog(f," 顯示結(jié)果",true);
Container diacp=dialog.getContentPane();
diacp.setLayout(new FlowLayout());
JLabel jLabel2 = new JLabel("您要查詢的結(jié)果",JLabel.CENTER);
jLabel2.setFont(new Font("宋體",Font.BOLD,20));
jLabel2.setForeground(Color.red);
diacp.add(jLabel2);
JTextArea jte=new JTextArea(10,50);
JScrollPane jscr=new JScrollPane(jte);
sbr=new JScrollBar(JScrollBar.HORIZONTAL,5,10,0,50);
sbr.setUnitIncrement(1);
sbr.setBlockIncrement(2);
jscr.add(sbr);
diacp.add(jscr);
dialog.setBounds(100,100,650,300);
dialog.setResizable(false);
dialog.show();
}
class TableDemo extends JFrame
{ final string[] str={"車次","始發(fā)站","終點站","歷經(jīng)里程","始發(fā)時間","到達時間","行走時間","票價"};
final Object[8][8] objData={
{"2510","齊齊哈爾","沈陽","837公里","8:29","19:10","10小時41分","55.00"}
{"N42","齊齊哈爾","哈爾濱東","129公里","10:51","12:28","1小時27分","12.00"}
{"4072","齊齊哈爾","佳木斯","129公里","7:11","19:49","12小時38分","53.00"}
{"N54","齊齊哈爾","雞西","129公里","21:57","23:26","1小時29分","12.00"}
{"T502","齊齊哈爾","哈爾濱","129公里","7:30","8:30","1小時0分","21.00"}
{"T506","齊齊哈爾","哈爾濱","129公里","13:40","14:40","1小時0分","21.00"}
{"2121","大連","佳木斯","507公里","5:37","13:04","7小時27分","64.00"}
{"N5","哈爾濱東","佳木斯","507公里","6:27","7:04","7小時4分","73.00"}
};
public TableDemo()
{super("火車查詢顯示結(jié)果:");
setTitle("關(guān)于");
int i,j;
TableModel tm=new Abstract TableModel();
{ public int getColumCount() {return str.length;}
public int getRowCount() {return objData.length;}
public Object getValueAt(int row,int col) {return objData[row][col];}
for(i=0;i<objData.length;i++)
{if(c1.equals(Object[i][1]) c=Object[i][1]
else c="未查到你所查詢的車次"
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if(cmd.equals("歡迎進入"))
{dial();}
else if(cmd.equals("返回"))
{ System.exit(0);}
if(cmd.equals("提交"))
{dial1();}
}
public void itemStateChanged(ItemEvent e)
{ }
}
class WinLis extends WindowAdapter
{public void windowClosing(WindowEvent e)
{System.exit(0);}
}
public class trian2
{
public static void main(String args[])
{new Frame1();}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -