【如何屏蔽 JFrame 标题栏的“关闭”按钮】

onefox 2004-12-06 06:31:27
偶用这样的代码无法实现

this.addWindowListener(new WindowAdapter() { //添加窗口关闭事件
public void windowClosing(WindowEvent e) {
return;
}
});


大家帮忙啊, 【隐藏】那个按钮或【使它时效】都可以。
...全文
299 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
onefox 2004-12-06
  • 打赏
  • 举报
回复
已解决!

求人不如求己。
onefox 2004-12-06
  • 打赏
  • 举报
回复
to: batfree(没有计算机的程序员)

能帮我找一下么, 给几个关键词也可以
onefox 2004-12-06
  • 打赏
  • 举报
回复
你自己拿去试试能不能用“关闭”按钮关掉窗口。

================ test.java =====================
import javax.swing.*;
import java.awt.event.*;

public class test extends JFrame {
public test() {
this.addWindowListener(new WindowAdapter() { //添加窗口关闭事件
public void windowClosing(WindowEvent e) {
///// Nothing /////
}
});

this.setSize(350,250);
this.show();
}

public static void main(String[] args) {
new test();
}
}
batfree 2004-12-06
  • 打赏
  • 举报
回复
好象可以生成一个什么都没有的窗口,具体怎么做我忘记了。但是见过介绍,
晨星 2004-12-06
  • 打赏
  • 举报
回复
还有,你不能再调用setDefaultCloseOperation函数,否则偶的那个就失效了。
晨星 2004-12-06
  • 打赏
  • 举报
回复
为什么不行?当然,没有隐藏起来或者灰掉,但是“实际上失效”。
onefox 2004-12-06
  • 打赏
  • 举报
回复
楼上的, 不行。
晨星 2004-12-06
  • 打赏
  • 举报
回复
JFrame frame = new JFrame();
......

给他提供一个啥也不做的空关闭事件响应函数就可以了。

当然,也可以不是空的,比如跳出个美女图片,总之不要调用一些关闭程序的函数就可以了。

frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {}
});
Java图片缩小与放大特效,// 图像缩小与放大演示   public class ScaleImageDemo extends JFrame {   private JPanel panel = new JPanel(); //面板panel用于容纳图像放大、缩孝还原按钮   private JButton jbFile = new JButton("打开图像文件"); //打开图像文件按钮   private JButton jbZoomIn = new JButton("放大"); //图像放大按钮   private JButton jbZoomOut = new JButton("缩小"); //图像缩小按钮   private JButton jbReset = new JButton("还原"); //图像还原按钮   ScalePane showImagePane = new ScalePane(); //创建showImagePane对象用于绘制图像   Container content = getContentPane(); //获得窗口的容器    //构造函数   public ScaleImageDemo() {   super("图像的缩小与放大"); //调用父类构造器设置窗口标题栏   //为按钮添加动作监听器   jbFile.addActionListener(new ButtonActionListener());   jbZoomIn.addActionListener(new ButtonActionListener());   jbZoomOut.addActionListener(new ButtonActionListener());   jbReset.addActionListener(new ButtonActionListener());   //把图像放大按钮、图像缩小按钮、图像还原按钮加入panel面板   panel.add(jbZoomIn);   panel.add(jbZoomOut);   panel.add(jbReset);   //把showImagePane文件选择组合框、控制面板、状态栏标签加入到窗口内容窗格   content.add(showImagePane, BorderLayout.CENTER);   content.add(jbFile, BorderLayout.NORTH);   content.add(panel, BorderLayout.SOUTH);   setSize(260, 200); //设置窗口大小   setVisible(true); //设置窗口可见   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序
Java播放wav音频功能的实现代码,播放wav音频,压缩包中带有测试音频,是否能播放 MP3,未知。   boolean looping = false; //是否循环播放   String[] choics = { "chimes.wav", "start.wav" }; //声音文件名数组   URL file1 = getClass().getResource(choics[0]); //声音文件1   URL file2 = getClass().getResource(choics[1]); //声音文件2   AudioClip sound1 = java.applet.Applet.newAudioClip(file1); //声音剪辑对象1   AudioClip sound2 = java.applet.Applet.newAudioClip(file2); //声音剪辑对象2   AudioClip chosenClip = sound1; //选择的声音剪辑对象   JComboBox jcbFiles = new JComboBox(choics); //文件选择组合框   JButton playButton = new JButton("播放"); //播放按钮   JButton loopButton = new JButton("循环播放"); //循环播放按钮   JButton stopButton = new JButton("停止"); //停止播放按钮   JLabel status = new JLabel("选择播放文件"); //状态栏标签   JPanel controlPanel = new JPanel(); //控制面板用于包容按钮   Container container = getContentPane(); //获得窗口内容窗格   public AudioPlayDemo() { //构造器    super("声音播放程序"); //调用父类构造器设置窗口标题栏    jcbFiles.setSelectedIndex(0); //设置组合框选择项    jcbFiles.addItemListener(this); //为播放按钮添加项目监听器    //为播放按钮、循环播放按钮、停止播放按钮添加动作监听器    playButton.addActionListener(this);    loopButton.addActionListener(this);    stopButton.addActionListener(this);    stopButton.setEnabled(false); //设置停止播放按钮不可用    //把播放按钮、循环播放按钮、停止播放按钮加入控制面板    controlPanel.add(playButton);    controlPanel.add(loopButton);    controlPanel.add(stopButton);    //把文件选择组合框、控制面板、状态栏标签加入到窗口内容窗格    container.add(jcbFiles, BorderLayout.NORTH);    container.add(controlPanel, BorderLayout.CENTER);    container.add(status, BorderLayout.SOUTH);    setSize(300, 130); //设置窗口大小    setVisible(true); //设置窗口可视    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序   }
多媒体处理包括多媒体技术的描述及其实现的源代码还有他的图品作品import java.applet.AudioClip; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.net.*; // 声音播放程序 public class AudioPlayDemo extends JFrame implements ActionListener, ItemListener { boolean looping = false; //是否循环播放 String[] choics = { "chimes.wav", "start.wav" }; //声音文件名数组 URL file1 = getClass().getResource(choics[0]); //声音文件1 URL file2 = getClass().getResource(choics[1]); //声音文件2 AudioClip sound1 = java.applet.Applet.newAudioClip(file1); //声音剪辑对象1 AudioClip sound2 = java.applet.Applet.newAudioClip(file2); //声音剪辑对象2 AudioClip chosenClip = sound1; //选择的声音剪辑对象 JComboBox jcbFiles = new JComboBox(choics); //文件选择组合框 JButton playButton = new JButton("播放"); //播放按钮 JButton loopButton = new JButton("循环播放"); //循环播放按钮 JButton stopButton = new JButton("停止"); //停止播放按钮 JLabel status = new JLabel("选择播放文件"); //状态栏标签 JPanel controlPanel = new JPanel(); //控制面板用于包容按钮 Container container = getContentPane(); //获得窗口内容窗格 public AudioPlayDemo() { //构造器 super("声音播放程序"); //调用父类构造器设置窗口标题栏 jcbFiles.setSelectedIndex(0); //设置组合框选择项 jcbFiles.addItemListener(this); //为播放按钮添加项目监听器 //为播放按钮、循环播放按钮、停止播放按钮添加动作监听器 playButton.addActionListener(this); loopButton.addActionListener(this); stopButton.addActionListener(this); stopButton.setEnabled(false); //设置停止播放按钮不可用 //把播放按钮、循环播放按钮、停止播放按钮加入控制面板 controlPanel.add(playButton); controlPanel.add(loopButton); controlPanel.add(stopButton); //把文件选择组合框、控制面板、状态栏标签加入到窗口内容窗格 container.add(jcbFiles, BorderLayout.NORTH); container.add(controlPanel, BorderLayout.CENTER); container.add(status, BorderLayout.SOUTH); setSize(300, 130); //设置窗口大小 setVisible(true); //设置窗口可视 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序 } //文件选择组合框事件处理 public void itemStateChanged(ItemEvent e) { if (jcbFiles.getSelectedIndex() == 0) { chosenClip = sound1; } else { chosenClip = sound2; } } //按钮事件处理 public void actionPerformed(ActionEvent event) { if (chosenClip == null) { status.setText("声音未载入"); return; //如果AudioClip对象为空,则直接返回 } Object source = event.getSource(); //获取用户洗涤激活的按钮 //播放按钮事件处理 if (source == playButton) { stopButton.setEnabled(true); //设置停止播放按钮可用 loopButton.setEnabled(true); //设置循环播放按钮可用 chosenClip.play(); //播放选择的声音剪辑对象一次 status.setText("正在播放"); //设置状态栏信息 } //循环播放按钮事件处理 if (source == loopButton) { looping = true; chosenClip.loop(); //循环播放选择的声音剪辑对象 loopButton.setEnabled(false); //设置循环播放按钮不可用 stopButton.setEnabled(true); //设置停止播放按钮可用 status.setText("正在循环播放"); //设置状态栏信息 } //停止播放按钮事件处理 if (source == stopButton) { if (looping) { looping = false; chosenClip.stop(); //停止循环播放选择的声音剪辑对象 loopButton.setEnabled(true); //设置循环播放按钮可用 } else { chosenClip.stop(); //停止播放选择的声音剪辑对象 } stopButton.setEnabled(false); //设置循环播放按钮可用 status.setText("停止播放"); //设置状态栏信息 } } public static void main(String s[]) { new AudioPlayDemo(); //创建AudioPlayDemo对象 } }
图书管理系统数据库源代码 //创建工程及设计主界面 public class Main extends JFrame { private static final JDesktopPane { DESKTOP_PANE=new JDesktopPane(); //桌面窗体 } public static void main(String[] args) //入口方法 { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //设置系统界面外观 new BookLogin(); //登录窗口 } catch(Exception ex) { ex.printStackTrace(); } } public static void addIFame(JInternalFrame iframe) //添加子窗体的方法 { DESKTOP_PANE。add(iframe); //新增子窗体 } public Main() { super(); //设置"关闭"按钮处理事件 setDefaultCloseOperation(WindowConstants。EXIT_ON_CLOSE); //创建工具栏 Toolkit tool=Toolkit,getDefaultToolkit(); //获得屏幕大小 Dimension screenSize=tool.getScreenSize(); setSize(800,600); //设置窗体大小 setLocation((screenSize.width—getWidth())/2,(screenSize。height- getHeight())/2; //设置窗体位置 setTitle("图书管理系统"); //设置窗体标题 JMenuBar menuBar=createMenu(); //创建菜单栏 setJMenuBar(menuBar); //设置菜单栏 JToolBar toolBar=createToolBar(); //创建工具栏的方法 getContentPane(),add(toolBar,BorderLayout。NORTH); //设置工具栏 final JLable lable=new JLable(); //创建一个标签,用来显示图片 lable。setBounds(0,0,0,0); //设置窗体的大小和位置 lable。setIcon(null); //窗体背景 DESKTOP_PANE.addComponentListener(new ComponentAdapter()) { public void componentResized(final ComponentEvent e) { Dimension size=e。getComponent().getSize(); //获得组建大小 lable。setSize(e.getComponent().getSize()); //设置标签大小 lable.setText("〈html>按钮 JButton bookAddButton=new JButton(MenuActions.BOOK_ADD); ImageIcon icon=new ImageIcon(Main.class.getResource("/bookAddtb.jpg")); //添加菜单栏图标 bookAddButton.setIcon(icon); //设置按钮图标 bookAddButton.setHideActionText(true); //显
public class ChatClient extends JFrame implements ActionListener{ String ip = "127.0.0.1";//连接到服务端的ip地址 int port = 8888;//连接到服务端的端口号 String userName = "匆匆过客";//用户名 int type = 0;//0表示未连接,1表示已连接 Image icon;//程序图标 JComboBox combobox;//选择发送消息的接受者 JTextArea messageShow;//客户端的信息显示 JScrollPane messageScrollPane;//信息显示的滚动条 JLabel express,sendToLabel,messageLabel ; JTextField clientMessage;//客户端消息的发送 JCheckBox checkbox;//悄悄话 JComboBox actionlist;//表情选择 JButton clientMessageButton;//发送消息 JTextField showStatus;//显示用户连接状态 Socket socket; ObjectOutputStream output;//网络套接字输出流 ObjectInputStream input;//网络套接字输入流 ClientReceive recvThread; //建立菜单栏 JMenuBar jMenuBar = new JMenuBar(); //建立菜单组 JMenu operateMenu = new JMenu ("操作(O)"); //建立菜单项 JMenuItem loginItem = new JMenuItem ("用户登录(I)"); JMenuItem logoffItem = new JMenuItem ("用户注销(L)"); JMenuItem exitItem=new JMenuItem ("退出(X)"); JMenu conMenu=new JMenu ("设置(C)"); JMenuItem userItem=new JMenuItem ("用户设置(U)"); JMenuItem connectItem=new JMenuItem ("连接设置(C)"); JMenu helpMenu=new JMenu ("帮助(H)"); JMenuItem helpItem=new JMenuItem ("帮助(H)"); //建立工具栏 JToolBar toolBar = new JToolBar(); //建立工具栏中的按钮组件 JButton loginButton;//用户登录 JButton logoffButton;//用户注销 JButton userButton;//用户信息的设置 JButton connectButton;//连接设置 JButton exitButton;//退出按钮 //框架的大小 Dimension faceSize = new Dimension(400, 600); JPanel downPanel ; GridBagLayout girdBag; GridBagConstraints girdBagCon; public ChatClient(){ init();//初始化程序 //添加框架的关闭事件处理 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.pack(); //设置框架的大小 this.setSize(faceSize); //设置运行时窗口的位置 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation( (int) (screenSize.width - faceSize.getWidth()) / 2, (int) (screenSize.height - faceSize.getHeight()) / 2); this.setResizable(false); this.setTitle("聊天室客户端"); //设置标题 //程序图标 icon = getImage("icon.gif"); this.setIconImage(icon); //设置程序图标 show(); //为操作菜单栏设置热键'V' operateMenu.setMnemonic('O'); //为用户登录设置快捷键为ctrl+i loginItem.setMnemonic ('I'); loginItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_I,InputEvent.CTRL_MASK)); //为用户注销快捷键为ctrl+l logoffItem.setMnemonic ('L'); logoffItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_L,InputEvent.CTRL_MASK)); //为退出快捷键为ctrl+x exitItem.setMnemonic ('X'); exitItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_X,InputEvent.CTRL_MASK)); //为设置菜单栏设置热键'C' conMenu.setMnemonic('C'); //为用户设置设置快捷键为ctrl+u userItem.setMnemonic ('U'); userItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_U,InputEvent.CTRL_MASK)); //为连接设置设置快捷键为ctrl+c connectItem.setMnemonic ('C'); connectItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_C,InputEvent.CTRL_MASK)); //为帮助菜单栏设置热键'H' helpMenu.setMnemonic('H'); //为帮助设置快捷键为ctrl+p helpItem.setMnemonic ('H'); helpItem.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_H,InputEvent.CTRL_MASK)); } /** * 程序初始化函数 */ public void init(){ Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); //添加菜单栏 operateMenu.add (loginItem); operateMenu.add (logoffItem); operateMenu.add (exitItem); jMenuBar.add (operateMenu); conMenu.add (userItem); conMenu.add (connectItem); jMenuBar.add (conMenu); helpMenu.add (helpItem); jMenuBar.add (helpMenu); setJMenuBar (jMenuBar); //初始化按钮 loginButton = new JButton("登录"); logoffButton = new JButton("注销"); userButton = new JButton("用户设置" ); connectButton = new JButton("连接设置" ); exitButton = new JButton("退出" ); //当鼠标放上显示信息 loginButton.setToolTipText("连接到指定的服务器"); logoffButton.setToolTipText("与服务器断开连接"); userButton.setToolTipText("设置用户信息"); connectButton.setToolTipText("设置所要连接到的服务器信息"); //将按钮添加到工具栏 toolBar.add(userButton); toolBar.add(connectButton); toolBar.addSeparator();//添加分隔栏 toolBar.add(loginButton); toolBar.add(logoffButton); toolBar.addSeparator();//添加分隔栏 toolBar.add(exitButton); contentPane.add(toolBar,BorderLayout.NORTH); checkbox = new JCheckBox("悄悄话"); checkbox.setSelected(false); actionlist = new JComboBox(); actionlist.addItem("微笑地"); actionlist.addItem("高兴地"); actionlist.addItem("轻轻地"); actionlist.addItem("生气地"); actionlist.addItem("小心地"); actionlist.addItem("静静地"); actionlist.setSelectedIndex(0); //初始时 loginButton.setEnabled(true); logoffButton.setEnabled(false); //为菜单栏添加事件监听 loginItem.addActionListener(this); logoffItem.addActionListener(this); exitItem.addActionListener(this); userItem.addActionListener(this); connectItem.addActionListener(this); helpItem.addActionListener(this); //添加按钮的事件侦听 loginButton.addActionListener(this); logoffButton.addActionListener(this); userButton.addActionListener(this); connectButton.addActionListener(this); exitButton.addActionListener(this); combobox = new JComboBox(); combobox.insertItemAt("所有人",0); combobox.setSelectedIndex(0); messageShow = new JTextArea(); messageShow.setEditable(false); //添加滚动条 messageScrollPane = new JScrollPane(messageShow, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); messageScrollPane.setPreferredSize(new Dimension(400,400)); messageScrollPane.revalidate(); clientMessage = new JTextField(23); clientMessage.setEnabled(false); clientMessageButton = new JButton(); clientMessageButton.setText("发送"); //添加系统消息的事件侦听 clientMessage.addActionListener(this); clientMessageButton.addActionListener(this); sendToLabel = new JLabel("发送至:"); express = new JLabel(" 表情: "); messageLabel = new JLabel("发送消息:"); downPanel = new JPanel(); girdBag = new GridBagLayout(); downPanel.setLayout(girdBag); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 0; girdBagCon.gridy = 0; girdBagCon.gridwidth = 5; girdBagCon.gridheight = 2; girdBagCon.ipadx = 5; girdBagCon.ipady = 5; JLabel none = new JLabel(" "); girdBag.setConstraints(none,girdBagCon); downPanel.add(none); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 0; girdBagCon.gridy = 2; girdBagCon.insets = new Insets(1,0,0,0); //girdBagCon.ipadx = 5; //girdBagCon.ipady = 5; girdBag.setConstraints(sendToLabel,girdBagCon); downPanel.add(sendToLabel); girdBagCon = new GridBagConstraints(); girdBagCon.gridx =1; girdBagCon.gridy = 2; girdBagCon.anchor = GridBagConstraints.LINE_START; girdBag.setConstraints(combobox,girdBagCon); downPanel.add(combobox); girdBagCon = new GridBagConstraints(); girdBagCon.gridx =2; girdBagCon.gridy = 2; girdBagCon.anchor = GridBagConstraints.LINE_END; girdBag.setConstraints(express,girdBagCon); downPanel.add(express); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 3; girdBagCon.gridy = 2; girdBagCon.anchor = GridBagConstraints.LINE_START; //girdBagCon.insets = new Insets(1,0,0,0); //girdBagCon.ipadx = 5; //girdBagCon.ipady = 5; girdBag.setConstraints(actionlist,girdBagCon); downPanel.add(actionlist); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 4; girdBagCon.gridy = 2; girdBagCon.insets = new Insets(1,0,0,0); //girdBagCon.ipadx = 5; //girdBagCon.ipady = 5; girdBag.setConstraints(checkbox,girdBagCon); downPanel.add(checkbox); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 0; girdBagCon.gridy = 3; girdBag.setConstraints(messageLabel,girdBagCon); downPanel.add(messageLabel); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 1; girdBagCon.gridy = 3; girdBagCon.gridwidth = 3; girdBagCon.gridheight = 1; girdBag.setConstraints(clientMessage,girdBagCon); downPanel.add(clientMessage); girdBagCon = new GridBagConstraints(); girdBagCon.gridx = 4; girdBagCon.gridy = 3; girdBag.setConstraints(clientMessageButton,girdBagCon); downPanel.add(clientMessageButton);

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧