?? detaildialog.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 + -