⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 detaildialog.java

📁 java实现的校园导航系统
💻 JAVA
字号:
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.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.DefaultButtonModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;


public class DetailDialog extends JDialog{
	private JPanel jContentPane = null;
	private static final long serialVersionUID = 1L;
	private JTextArea infoTextArea = null;
	String name = "gilyou";
	String introduction = "gilyou system";
	private JButton okButton = null;
	public JLabel imageLabel = null;
	/**
	 * This is the default constructor
	 */
	public DetailDialog(JFrame frame, ImageIcon icon, String name, String introduction) {
		super(frame,"详细信息",true);
		initialize();
		if(icon != null)
			this.imageLabel.setIcon(icon);
		else
			this.imageLabel.setText("对不起,暂无照片");
		this.name = name;
		this.introduction = introduction;
	}
	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(840, 427);
		this.setContentPane(getJContentPane());
		this.setResizable(false);
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				DetailDialog.this.dispose();
			}
			public void windowOpened(WindowEvent e){
				DetailDialog.this.okButton.requestFocus();
			}
		});
		this.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - this.getSize().width)/2,(Toolkit.getDefaultToolkit().getScreenSize().height - this.getSize().height)/2);

	}
	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			imageLabel = new JLabel();
			imageLabel.setBounds(new Rectangle(2, 0, 569, 361));
			imageLabel.setBackground(Color.pink);
			imageLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
			imageLabel.setHorizontalAlignment(SwingConstants.CENTER);
			imageLabel.setHorizontalTextPosition(SwingConstants.CENTER);
			imageLabel.setForeground(Color.cyan);
			imageLabel.setOpaque(true);
			imageLabel.setToolTipText("相关图片");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setOpaque(false);
			jContentPane.add(getInfoTextArea());
			jContentPane.add(getOkButton());
			jContentPane.add(imageLabel, null);
		}
		return jContentPane;
	}
	/**
	 * This method initializes infoTextArea	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	private JTextArea getInfoTextArea() {
		if (infoTextArea == null) {
			infoTextArea = new JTextArea();
			infoTextArea.setBounds(new Rectangle(571, -1, 260, 362));
			infoTextArea.setOpaque(true);
			infoTextArea.setToolTipText("详细说明");
			infoTextArea.setBorder(null);
			infoTextArea.setBackground(Color.red);
			infoTextArea.setFont(new Font("\u5b8b\u4f53", Font.BOLD, 24));
			infoTextArea.setWrapStyleWord(true);
			infoTextArea.setFocusable(false);
			if(name != null && introduction != null){
				infoTextArea.setText("景点: " + name + "\n" + "详细信息Here: " + introduction);
			}
		}
		return infoTextArea;
	}
	/**
	 * This method initializes okButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getOkButton() {
		if (okButton == null) {
			DefaultButtonModel defaultButtonModel = new DefaultButtonModel();
			defaultButtonModel.setArmed(true);
			okButton = new JButton();
			okButton.setBounds(new Rectangle(387, 366, 57, 21));
			okButton.setMargin(new Insets(0,0,0,0));
			okButton.setToolTipText("返回原界面");
			okButton.setForeground(SystemColor.activeCaption);
			okButton.setBorderPainted(false);
			okButton.setOpaque(true);
			okButton.setModel(defaultButtonModel);
			okButton.setText("确定");
			okButton.addMouseListener(new MouseAdapter(){
				public void mouseEntered(MouseEvent e){
					okButton.setBackground(Color.red);
				}
				public void mouseExited(MouseEvent e){
					okButton.setBackground(Color.white);
				}
			});
			okButton.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){

					DetailDialog.this.dispose();
				}
			});
		}
		return okButton;
	}
}  //  @jve:decl-index=0:visual-constraint="237,11"

⌨️ 快捷键说明

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