📄 frame.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class frame extends JFrame
{
JPanel jp,jpl,jpr;
JLabel jl;
JButton jb1,jb2,jb3;
Jp1 jp1;
Jp2 jp2;
Jp3 jp3;
CardLayout cl;
public frame()
{
setTitle("南昌市公交查询系统");
jp=new JPanel();
jpl=new JPanel();
jpr=new JPanel();
jp1=new Jp1();
jp2=new Jp2();
jp3=new Jp3();
jp=(JPanel)this.getContentPane();
jl=new JLabel("南昌市公交查询系统");
jb1=new JButton("换乘查询");
jb2=new JButton("路线查询");
jb3=new JButton("站点查询");
jp.setLayout(new BorderLayout());
jpl.setLayout(new GridLayout(3,1));
cl=new CardLayout();
jpr.setLayout(cl);
jpl.add(jb1);
jpl.add(jb2);
jpl.add(jb3);
jp.add(jl,BorderLayout.NORTH);
jp.add(jpl,BorderLayout.WEST);
jpr.add("first",jp1);
jpr.add("second",jp2);
jpr.add("last",jp3);
jp.add(jpr,BorderLayout.CENTER);
jl.setBorder(new JTextField().getBorder());
jl.setHorizontalAlignment(SwingConstants.CENTER);
jl.setFont(new java.awt.Font("楷体", 0, 15));
jb1.setFont(new java.awt.Font("楷体", 0, 12));
jb2.setFont(new java.awt.Font("楷体", 0, 12));
jb3.setFont(new java.awt.Font("楷体", 0, 12));
this.setSize(450,300);
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
setLocation( ( ( screenDim.width - getSize().width ) / 2 ),( ( screenDim.height - getSize().height ) / 2) );
jb1.addActionListener(new JBL());
jb2.addActionListener(new JBL());
jb3.addActionListener(new JBL());
}
public static void main(String args[])
{
frame fra=new frame();
fra.setUIFont(new javax.swing.plaf.FontUIResource("楷体",Font.PLAIN,12));
fra.setVisible(true);
}
protected void processWindowEvent(WindowEvent eee)
{
if (eee.getID()==WindowEvent.WINDOW_CLOSING)
{
System.exit(0);
}
}
public static void setUIFont(javax.swing.plaf.FontUIResource f)
{
java.util.Enumeration keys = UIManager.getDefaults().keys();
while(keys.hasMoreElements())
{
Object key = keys.nextElement();
Object value = UIManager.get(key);
if(value instanceof javax.swing.plaf.FontUIResource)
{
UIManager.put(key,f);
}
}
}
public class JBL implements ActionListener
{
public void actionPerformed(ActionEvent e1)
{
if(e1.getSource()==jb1)
{
cl.first(jpr);
}
if(e1.getSource()==jb2)
{
cl.first(jpr);
cl.next(jpr);
}
if(e1.getSource()==jb3)
{
cl.last(jpr);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -