📄 pnlsi.java
字号:
/*此类负责公交公司的界面的规划与功能的实现*/
package pro;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class PnlSi extends JPanel implements java.awt.event.ActionListener
{
JLabel jLabel1 = new JLabel();
TitledBorder titledBorder1 = new TitledBorder("");
JButton btLongRang = new JButton();
JButton btnJiaoTong = new JButton();
JButton btnGufen = new JButton();
JButton btnSanYe = new JButton();
JButton btnJiaNian = new JButton();
JButton btnHengTong = new JButton();
JButton btnKaicheng = new JButton();
JButton btnWanZhong = new JButton();
JButton btnZhongWang = new JButton();
JButton btnHongGuang = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea TxtArea1 = new JTextArea();
public PnlSi()
{
this.setLayout(null);
this.setBorder(titledBorder1);
jLabel1.setFont(new java.awt.Font("Dialog", Font.BOLD | Font.ITALIC, 18));
jLabel1.setForeground(new Color(249, 79, 0));
jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
jLabel1.setText("公交公司具体信息");
jLabel1.setBounds(new Rectangle(4, 1, 600, 45));
btLongRang.setBounds(new Rectangle(2, 50, 192, 26));
btLongRang.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btLongRang.setForeground(Color.red);
btLongRang.setText("湖南龙骧巴士有限责任公司");
btnJiaoTong.setBounds(new Rectangle(2, 81, 192, 26));
btnJiaoTong.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnJiaoTong.setForeground(Color.red);
btnJiaoTong.setText("湖南巴士公共交通有限公司");
btnGufen.setBounds(new Rectangle(2, 111, 192, 26));
btnGufen.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnGufen.setForeground(Color.red);
btnGufen.setText("长沙巴士股份有限公司");
btnSanYe.setBounds(new Rectangle(2, 142, 192, 26));
btnSanYe.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnSanYe.setForeground(Color.red);
btnSanYe.setText("长沙市三叶联营公共汽车公司");
btnJiaNian.setBounds(new Rectangle(2, 173, 192, 26));
btnJiaNian.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnJiaNian.setForeground(Color.red);
btnJiaNian.setText("长沙嘉年华巴士有限公司");
btnHengTong.setBounds(new Rectangle(2, 203, 192, 26));
btnHengTong.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnHengTong.setForeground(Color.red);
btnHengTong.setText("长沙恒通巴士有限责任公司");
btnKaicheng.setBounds(new Rectangle(2, 234, 192, 26));
btnKaicheng.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnKaicheng.setForeground(Color.red);
btnKaicheng.setText("长沙凯程巴士有限责任公司");
btnWanZhong.setBounds(new Rectangle(2, 265, 192, 26));
btnWanZhong.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnWanZhong.setForeground(Color.red);
btnWanZhong.setText("长沙万众公共汽车有限公司");
btnZhongWang.setBounds(new Rectangle(2, 295, 192, 26));
btnZhongWang.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnZhongWang.setForeground(Color.red);
btnZhongWang.setText("长沙众旺公交有限责任公司");
btnHongGuang.setBounds(new Rectangle(2, 326, 192, 26));
btnHongGuang.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
btnHongGuang.setForeground(Color.red);
btnHongGuang.setText("长沙红光巴士有限公司");
jScrollPane1.setBounds(new Rectangle(196, 50, 422, 410));
// TxtArea1.setBackground(Color.gray);
TxtArea1.setLineWrap(true);
TxtArea1.setEditable(false);
TxtArea1.setText("");
jScrollPane1.getViewport().add(TxtArea1);
btLongRang.setActionCommand("btLongRang");
btnJiaoTong.setActionCommand("btnJiaoTong");
btnGufen.setActionCommand("btnGufen");
btnSanYe.setActionCommand("btnSanYe");
btnJiaNian.setActionCommand("btnJiaNian");
btnHengTong.setActionCommand("btnHengTong");
btnWanZhong.setActionCommand("btnWanZhong");
btnZhongWang.setActionCommand("btnZhongWang");
btnHongGuang.setActionCommand("btnHongGuang");
btnKaicheng.setActionCommand("btnKaicheng");
btLongRang.addActionListener(this);
btnJiaoTong.addActionListener(this);
btnGufen.addActionListener(this);
btnSanYe.addActionListener(this);
btnJiaNian.addActionListener(this);
btnHengTong.addActionListener(this);
btnWanZhong.addActionListener(this);
btnZhongWang.addActionListener(this);
btnHongGuang.addActionListener(this);
btnKaicheng.addActionListener(this);
this.add(jLabel1);
this.add(btLongRang);
this.add(btnJiaoTong);
this.add(btnGufen);
this.add(btnSanYe);
this.add(btnJiaNian);
this.add(btnHengTong);
this.add(btnKaicheng);
this.add(btnWanZhong);
this.add(btnZhongWang);
this.add(btnHongGuang);
this.add(jScrollPane1);
this.setSize(new Dimension(450, 580));
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
String ary = ae.getActionCommand();
if(ary.equals("btLongRang"))
{
try {
File file = new File("湖南龙骧巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnJiaoTong"))
{
try {
File file = new File("湖南巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnGufen"))
{
try {
File file = new File("长沙巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnSanYe"))
{
try {
File file = new File("长沙三叶.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnJiaNian"))
{
try {
File file = new File("嘉年华巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnHengTong"))
{
try {
File file = new File("恒通巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnWanZhong"))
{
try {
File file = new File("长沙万众.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
if(ary.equals("btnZhongWang"))
{
try {
File file = new File("长沙众旺.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnHongGuang"))
{
try {
File file = new File("红光巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
else if(ary.equals("btnKaicheng"))
{
try {
File file = new File("凯程巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
if(ary.equals("btLongRang"))
{
try {
File file = new File("湖南龙骧巴士.txt");
FileInputStream fis = new FileInputStream(file);
byte[] buf = new byte[(int)(file.length())];
fis.read(buf);
String str = new String(buf);
// System.out.println(str);
TxtArea1.setText(str);
fis.close();
}
catch (FileNotFoundException fnfe)
{
System.out.println("文件打开失败。");
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
public void paintComponent(Graphics g)//传一个画笔进来!
{
javax.swing.ImageIcon ii = new ImageIcon("img/shanZhan.jpg");//把图片读出来!
g.drawImage(ii.getImage(), 0, 0, this);//画画,定位置!
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -