📄 test.java
字号:
/**
* Email: taorundong@126.com
*
* @author taorundong
* @version 1.00 07/02/04
*/
//this class will show the main frame of the program
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
import java.net.URL;
public class Test extends JFrame implements ActionListener,MouseListener{
private
JMenuBar menuBar = null;
JMenu fileMenu = null;
JMenuItem itemExit = null;
JMenu helpMenu = null;
JMenuItem itemAbout = null;
JMenuItem itemFullScreen = null;
JMenuItem itemNormalSize = null;
URL musicURL = null;
AudioClip music = null;
MyPanel chatingPanel = null;
int clickTimes = 0;
int windowState = 0;
Test(String title){
super(title);
new MusicThread("music\\start.wav");
setMouseListener();
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
itemExit = new JMenuItem("Exit");
itemExit.setToolTipText("退出");
helpMenu = new JMenu("Help");
itemAbout = new JMenuItem("About");
itemAbout.setToolTipText("关于");
itemFullScreen = new JMenuItem("Full Screen");
itemFullScreen.setToolTipText("全屏");
itemNormalSize = new JMenuItem("Normal Size");
itemNormalSize.setToolTipText("返回");
chatingPanel = new MyPanel();
setMenu();
setScreenSize();
showChatingPanel();
this.setVisible(true);
this.setResizable(false);
// chatingPanel.startInputThread();
}
public void setMouseListener(){
this.addMouseListener(this);
}
public void mouseEntered(MouseEvent e){
if(e.getSource()==this){
this.setCursor(Cursor.HAND_CURSOR);
}
}
public void mousePressed(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
//click the screen twice to full screen
public void mouseClicked(MouseEvent e){
if(clickTimes<1){
clickTimes += 1;
return;
}
else if(windowState!=1){
setFullScreen();
clickTimes = 0;
windowState = 1;
return;
}
else{
setScreenSize();
clickTimes = 0;
windowState = 0;
}
}
public void showChatingPanel(){
Container con = this.getContentPane();
con.add(chatingPanel);
con.validate();
}
public void setMenu(){
itemExit.addActionListener(this);
itemAbout.addActionListener(this);
itemFullScreen.addActionListener(this);
itemNormalSize.addActionListener(this);
fileMenu.add(itemFullScreen);
fileMenu.add(itemNormalSize);
fileMenu.add(itemExit);
helpMenu.add(itemAbout);
menuBar.add(fileMenu);
menuBar.add(helpMenu);
menuBar.validate();
this.setJMenuBar(menuBar);
this.setIconImage(this.getToolkit().getImage("picture\\11.gif"));//Set icon image
}
public void setScreenSize(){
Dimension screen = this.getToolkit().getScreenSize();
this.setBounds(200,100,2*screen.width/3+50,2*screen.height/3);
this.setResizable(false);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
}
public void setFullScreen(){
Dimension screen = this.getToolkit().getScreenSize();
this.setBounds(0,0,screen.width,screen.height);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==itemExit){
this.dispose();
System.exit(0);
}
if(e.getSource()==itemAbout){
new About("About");
}
if(e.getSource()==itemFullScreen){
setFullScreen();
}
if(e.getSource()==itemNormalSize){
setScreenSize();
}
}
public void insertMusic(String musicName){
musicURL = this.getClass().getResource(musicName);
music = Applet.newAudioClip(musicURL);
music.play();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -