📄 frame.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.IOException;
import net.jxta.exception.PeerGroupException;
public class frame extends Frame implements ActionListener
{
MenuBar mnub;
Menu file,help;
MenuItem exit,about;
FilesharingPanel panel;
frame() throws PeerGroupException, IOException
{
super("P2P文件共享");
setVisible(true);
setBackground(Color.lightGray);
setResizable(false); //设置窗口大小不可调
setLayout(null);
StartService.start();
mnub =new MenuBar();
setMenuBar(mnub);
file=new Menu(" 文件 ");
help=new Menu(" 帮助 ");
exit=new MenuItem(" 退出 ");
about=new MenuItem("关于P2P文件共享系统");
panel=new FilesharingPanel();
mnub.add(file);
mnub.add(help);
file.add(exit);
help.add(about);
this.add(panel);
pack();//初始化看到窗口中所有对象
setBounds(20,20,568,455); //设置窗口位置、大小
exit.addActionListener(this);
about.addActionListener(this);
addWindowListener(
new WindowAdapter(){ //事件适配器(Adapter)类
public void windowClosing(WindowEvent e)
{
setVisible(false);
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==about)
{
HelpDialog hpd=new HelpDialog(frame.this,"关于P2P文件共享系统",true); //"true"表示采用模态对话框
hpd.setVisible(true);
}
else if(e.getSource()==exit)
{
setVisible(false);
System.exit(0);
}
}
public static void main(String[] args) throws PeerGroupException, IOException
{
frame frm=new frame();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -