?? ch10ex19.java
字號(hào):
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.Timer.*;
class HelpAboutDialog extends JFrame{
private JDialog helpAbout;
private JButton okButton,frameButton;;
private Container contentPanel;
private JFrame frame;
private Timer myTimer;
private int Counter=0;
public HelpAboutDialog(){
super("JDialog示范");
setSize(400,300);
contentPanel=getContentPane();
contentPanel.setLayout(new BorderLayout());
Font ft=new Font("宋體",Font.BOLD,30);
frameButton=new JButton("測(cè)試系統(tǒng)");
frameButton.setFont(ft);
contentPanel.add(frameButton,BorderLayout.CENTER);
frameButton.addActionListener(new CalButton());
addWindowListener(new WindowDestroyer());
Font ft1=new Font("宋體",Font.PLAIN,14);
frame=new JFrame("對(duì)話框");
helpAbout=new JDialog(frame,"parent container",true);
Container dialogcp=helpAbout.getContentPane();
dialogcp.setLayout(new BorderLayout());
JLabel imageLabel=new JLabel(new ImageIcon("javalogo.gif"));
dialogcp.add(imageLabel,BorderLayout.WEST);
JPanel authorInfoPane=new JPanel();
authorInfoPane.setLayout(new GridLayout(1,1));
JTextArea aboutContent=new JTextArea("高等教育出版社,2005年5月,丁岳偉、彭登陸編著");
aboutContent.setFont(ft1);
authorInfoPane.add(aboutContent);
dialogcp.add(authorInfoPane,BorderLayout.NORTH);
JPanel OKPane=new JPanel();
okButton=new JButton("確定",new ImageIcon("animal.gif"));
okButton.setFont(ft1);
ImageIcon rollover = new ImageIcon("tom.gif");
ImageIcon general = new ImageIcon("animal.gif");
ImageIcon press = new ImageIcon("cat.gif");
okButton.setRolloverEnabled(true);
okButton.setIcon(general);
okButton.setRolloverIcon(rollover);
okButton.setPressedIcon(press);
okButton.addActionListener(new TimerAction());
OKPane.add(okButton);
dialogcp.add(OKPane,BorderLayout.SOUTH);
JPanel sysInfoPane=new JPanel();
sysInfoPane.setLayout(new GridLayout(5,1));
sysInfoPane.setBorder(BorderFactory.createLoweredBevelBorder());
sysInfoPane.setBackground(Color.white);
JLabel userName=new JLabel("用戶名:"+System.getProperty("user.name"));
JLabel osName=new JLabel("操作系統(tǒng):"+System.getProperty("os.name"));
JLabel javaVersion=new JLabel("安裝的Java SDK的版本號(hào):"+System.getProperty("java.version"));
JLabel totalMemory=new JLabel("Java虛擬機(jī)可能使用的總內(nèi)存數(shù):"+Runtime.getRuntime().totalMemory()+"字節(jié)數(shù)" );
JLabel freeMemory=new JLabel("Java虛擬機(jī)所剩余的內(nèi)存數(shù)"+Runtime.getRuntime().freeMemory()+"字節(jié)數(shù)" );
userName.setFont(ft1);
osName.setFont(ft1);
javaVersion.setFont(ft1);
totalMemory.setFont(ft1);
freeMemory.setFont(ft1);
sysInfoPane.add(userName);
sysInfoPane.add(osName);
sysInfoPane.add(javaVersion);
sysInfoPane.add(totalMemory);
sysInfoPane.add(freeMemory);
dialogcp.add(sysInfoPane,BorderLayout.CENTER);
myTimer=new Timer(1000,new TimerAction());
myTimer.start();
addWindowListener(new WindowDestroyer());
}
class TimerAction implements ActionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource()==okButton)
helpAbout.dispose();
else if(e.getSource()==myTimer){
Counter++;
helpAbout.setTitle("當(dāng)前的定時(shí)器的值為:"+Counter+"秒");
}
}
}
class CalButton implements ActionListener{
public void actionPerformed(ActionEvent e){
helpAbout.setSize(400,300);
helpAbout.setLocation(100,100);
helpAbout.setVisible(true);
}
}
}
class WindowDestroyer extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
public class ch10ex19{
public static void main(String args[]) {
HelpAboutDialog win=new HelpAboutDialog();
win.setVisible(true);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -