窗口问题

xjp6688 2006-06-16 09:16:24
怎样把JFRAME窗口的"X"关闭按钮变成灰色?
或者把"X"这个按钮去掉?
...全文
131 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjp6688 2006-06-20
  • 打赏
  • 举报
回复
多谢!
congliu 2006-06-19
  • 打赏
  • 举报
回复
我以前写过的code,生成无边框的窗口
import java.awt.*;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.event.MouseInputAdapter;

public class UndecoratedFrame extends JFrame
{
private static final int TITLE_HEIGHT = 20;

public UndecoratedFrame() throws HeadlessException
{
super();
setUndecorated(true);

MouseHandler ml = new MouseHandler();
addMouseListener(ml);
addMouseMotionListener(ml);
}

public UndecoratedFrame(String title) throws HeadlessException
{
super(title);
setUndecorated(true);

MouseHandler ml = new MouseHandler();
addMouseListener(ml);
addMouseMotionListener(ml);
}

public Insets getInsets()
{
return new Insets(TITLE_HEIGHT, 1, 1, 1);
}

public void paint(Graphics g)
{
super.paint(g);
g.setColor(new Color(0, 0, 128));
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
g.fillRect(0, 0, getWidth(), TITLE_HEIGHT);

FontMetrics fm = g.getFontMetrics();
g.setColor(Color.white);
g.drawString(getTitle(), 2, (TITLE_HEIGHT - fm.getHeight()) / 2 + fm.getAscent());
}

private class MouseHandler extends MouseInputAdapter
{
private Point point;

public void mousePressed(MouseEvent e)
{
if (e.getY() <= TITLE_HEIGHT) {
this.point = e.getPoint();
}
}

public void mouseDragged(MouseEvent e)
{
if (point != null) {
setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));

Point p = e.getPoint();
int dx = p.x - point.x;
int dy = p.y - point.y;

int x = getX();
int y = getY();
setLocation(x + dx, y + dy);
}
}

public void mouseReleased(MouseEvent e)
{
point = null;
setCursor(Cursor.getDefaultCursor());
}
}

public static void main(String[] args)
{
JFrame f = new UndecoratedFrame("Undecorated Frame");
f.getContentPane().add(new JLabel("Hello World!", JLabel.CENTER), BorderLayout.CENTER);
f.setSize(400, 400);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}

}

xjp6688 2006-06-17
  • 打赏
  • 举报
回复
不太懂,谁给解释一下?
或者还有其他的方法没有?
xjp6688 2006-06-16
  • 打赏
  • 举报
回复
多谢,没有其他的方法了吗?
如果修改frame的实现,怎么修改呢?
stamp80 2006-06-16
  • 打赏
  • 举报
回复
我不能说不行,呵呵,打错了
stamp80 2006-06-16
  • 打赏
  • 举报
回复
这个要修改frame的实现了,我不能做不行,只是这么作了,程序也没有通用型
yitianyidian 2006-06-16
  • 打赏
  • 举报
回复
我也不会,前几天看到这个问题了,有位大侠给了如下答案,我也还不太懂,你看看吧
function IfWindowClosed()
  {  
    var win = null;
    try
    {
      window.opener.name = "ss";
      if ( window.opener.name != "ss" )
      {
        win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000");
        window.setTimeout("window.close();",0);
      }
      window.opener.name = "";
    }
    catch(e)
    {
      win = window.open("quit.asp","","width=100,height=100,left=10000,top=10000");
      window.setTimeout("window.close();",0);
    }
  }
  
  window.setInterval("IfWindowClosed()",100);
  window.setTimeout("window.close();",510);

62,614

社区成员

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

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