📄 layoutapplicationframe.java~12~
字号:
package layoutapplication;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <p>Title: Layout Application</p>
*
* <p>Description: Using the different layout</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: Aptech</p>
*
* @author Michael
* @version 1.0
*/
public class LayoutApplicationFrame extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
JButton btnNorth = new JButton();
JButton btnWest = new JButton();
JButton btnSouth = new JButton();
JButton btnEast = new JButton();
JPanel pnlCenter = new JPanel();
JLabel lblMessage = new JLabel();
JTextField txtMessage = new JTextField();
FlowLayout flowLayout1 = new FlowLayout();
public LayoutApplicationFrame() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(400, 300));
setTitle("欢迎使用布局管理器");
btnNorth.setFont(new java.awt.Font("", Font.PLAIN, 11));
btnNorth.setText("北");
btnNorth.addActionListener(new
LayoutApplicationFrame_btnNorth_actionAdapter(this));
btnWest.setFont(new java.awt.Font("", Font.PLAIN, 11));
btnWest.setText("西");
btnWest.addActionListener(new
LayoutApplicationFrame_btnWest_actionAdapter(this));
btnSouth.setFont(new java.awt.Font("", Font.PLAIN, 11));
btnSouth.setText("南");
btnSouth.addActionListener(new
LayoutApplicationFrame_btnSouth_actionAdapter(this));
btnEast.setFont(new java.awt.Font("Tahoma", Font.PLAIN, 11));
btnEast.setText("东");
btnEast.addActionListener(new
LayoutApplicationFrame_btnEast_actionAdapter(this));
pnlCenter.setFont(new java.awt.Font("", Font.PLAIN, 11));
pnlCenter.setLayout(flowLayout1);
lblMessage.setFont(new java.awt.Font("", Font.PLAIN, 11));
lblMessage.setHorizontalAlignment(SwingConstants.CENTER);
lblMessage.setText("消息:");
txtMessage.setFont(new java.awt.Font("", Font.PLAIN, 11));
txtMessage.setPreferredSize(new Dimension(150, 20));
txtMessage.setText("");
contentPane.add(btnWest, java.awt.BorderLayout.WEST);
contentPane.add(btnSouth, java.awt.BorderLayout.SOUTH);
contentPane.add(btnEast, java.awt.BorderLayout.EAST);
contentPane.add(pnlCenter, java.awt.BorderLayout.CENTER);
pnlCenter.add(lblMessage);
pnlCenter.add(txtMessage);
contentPane.add(btnNorth, java.awt.BorderLayout.NORTH);
}
public void btnWest_actionPerformed(ActionEvent e) {
txtMessage.setText("你按下了按钮“西”");
}
public void btnSouth_actionPerformed(ActionEvent e) {
txtMessage.setText("你按下了按钮“南”");
}
public void btnEast_actionPerformed(ActionEvent e) {
txtMessage.setText("你按下了按钮“东”");
}
public void btnNorth_actionPerformed(ActionEvent e) {
txtMessage.setText("你按下了按钮“北”");
}
}
class LayoutApplicationFrame_btnNorth_actionAdapter implements ActionListener {
private LayoutApplicationFrame adaptee;
LayoutApplicationFrame_btnNorth_actionAdapter(LayoutApplicationFrame
adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnNorth_actionPerformed(e);
}
}
class LayoutApplicationFrame_btnEast_actionAdapter implements ActionListener {
private LayoutApplicationFrame adaptee;
LayoutApplicationFrame_btnEast_actionAdapter(LayoutApplicationFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnEast_actionPerformed(e);
}
}
class LayoutApplicationFrame_btnSouth_actionAdapter implements ActionListener {
private LayoutApplicationFrame adaptee;
LayoutApplicationFrame_btnSouth_actionAdapter(LayoutApplicationFrame
adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSouth_actionPerformed(e);
}
}
class LayoutApplicationFrame_btnWest_actionAdapter implements ActionListener {
private LayoutApplicationFrame adaptee;
LayoutApplicationFrame_btnWest_actionAdapter(LayoutApplicationFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnWest_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -