viewpanel.java

来自「java实现的校园导航系统」· Java 代码 · 共 98 行

JAVA
98
字号
package gilyou.liu;

import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;


public class ViewPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	public JButton showDetailButton = null;
	public String name = null;
	public String introduction = null;
	public JTextArea detailTextArea = null;
	/**
	 * This is the default constructor
	 */
	public ViewPanel() {
		super();
		initialize();
		this.setSize(this.getPreferredSize());
	}
	public ViewPanel(String name,String introduction){
		super();
		initialize();
		this.name = name;
		this.introduction = introduction;
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(87, 62);
		this.setLayout(null);
		this.setBackground(Color.blue);
		this.setForeground(Color.blue);
		this.setFont(new Font("Dialog", Font.BOLD, 12));
		this.add(getShowDetailButton(), null);
		this.add(getDetailTextArea(), null);
		this.setOpaque(false);
	}
	/**
	 * This method initializes showDetailButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getShowDetailButton() {
		if (showDetailButton == null) {
			showDetailButton = new JButton();
			showDetailButton.setBounds(new Rectangle(25, 43, 40, 18));
			showDetailButton.setMargin(new Insets(0, 0, 0, 0));
			showDetailButton.setForeground(SystemColor.inactiveCaption);
			showDetailButton.setText("Detail");
			showDetailButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
			showDetailButton.setToolTipText("显示详细信息");
			showDetailButton.addMouseListener(new MouseAdapter(){
				public void mouseEntered(MouseEvent e){
					showDetailButton.setBackground(Color.red);
				}
				public void mouseExited(MouseEvent e){
					showDetailButton.setBackground(Color.white);
				}
			});
		}
		return showDetailButton;
	}
	/**
	 * This method initializes detailTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	public JTextArea getDetailTextArea() {
		if (detailTextArea == null) {
			detailTextArea = new JTextArea();
			detailTextArea.setBounds(new Rectangle(0, 0, 87, 42));
			detailTextArea.setEditable(false);
			detailTextArea.setFont(new Font("",Font.BOLD,12));
			detailTextArea.setWrapStyleWord(false);
			detailTextArea.setLineWrap(true);
			detailTextArea.setOpaque(false);
			detailTextArea.setBackground(Color.gray);
		}
		return detailTextArea;
	}

}  //  @jve:decl-index=0:visual-constraint="430,186"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?