📄 superdialog.java
字号:
package super_cpt;
import java.awt.event.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
public class SuperDialog extends Dialog{
/**
* @param args
*/
public Dimension fullSize=new Dimension();
public BufferedImage backImage;
public BufferedImage offImage;
public Graphics2D offG;
private Point mousepnt=new Point();//缓存
private Shape clshape;//关闭按钮
private boolean pressed=false;//是否按下
public SuperDialog(String str,Frame f,boolean bool)
{//构造函数
super(f,str,bool);
setLayout(null);
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
if(e.getButton()!=MouseEvent.BUTTON1)return;
mousepnt.setLocation(e.getX(),e.getY());
if(clshape.contains(e.getX(),e.getY()))
{
pressed=true;
repaint(0,0,getWidth(),20);
}
}
public void mouseReleased(MouseEvent e)
{
if(e.getButton()!=MouseEvent.BUTTON1)return;
pressed=false;
repaint(0,0,getWidth(),20);
if(clshape.contains(e.getX(),e.getY()))
{
setVisible(false);
}
}
});
this.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e)
{
int dx=e.getX()-mousepnt.x,dy=e.getY()-mousepnt.y;
setLocation(getX()+dx,getY()+dy);
}
});
this.setUndecorated(true);
}
public void initBackImage(int w,int h)
{//初始化背景图像
backImage=this.getGraphicsConfiguration().createCompatibleImage(getWidth(),getHeight());
Graphics2D g2=backImage.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
//填充背景
g2.setColor(Color.WHITE);
g2.fillRect(0,0,getWidth(),getHeight());
//填充渐变
Color midcolor=new Color(210,210,210);
GradientPaint paint=new GradientPaint(0,0,midcolor,0,12,Color.WHITE);
g2.setPaint(paint);
g2.fillRect(0,0,getWidth(),12);
paint=new GradientPaint(0,12,Color.WHITE,0,24,midcolor);
g2.setPaint(paint);
g2.fillRect(0,10,getWidth(),12);
//绘制边框
paint=new GradientPaint(0,0,Color.BLUE,0,12,midcolor);
g2.setPaint(paint);
g2.fillRect(0,0,4,12);
//g2.fillRect(getWidth()-4,0,4,10);
paint=new GradientPaint(0,12,midcolor,0,24,Color.BLUE);
g2.setPaint(paint);
g2.fillRect(0,12,4,12);
//g2.fillRect(getWidth()-4,10,4,8);
g2.fillRect(0,22,4,getHeight()-8);
//g2.fillRect(getWidth()-4,8,4,getHeight()-8);
//绘制外框
g2.setColor(Color.GRAY);
//g2.drawLine(0,15,getWidth(),15);
g2.setStroke(new BasicStroke(1.8f));
g2.drawRect(0,0,w-1,h-1);
g2.dispose();
clshape=new RoundRectangle2D.Float(w-19,5,12,12,8,8);
}
private final static Color pressedColor=Color.GRAY,pressColor=Color.RED;
public void update(Graphics g)
{//刷新
int w=getWidth(),h=getHeight();
if(offImage==null || offG==null)
{
offImage=this.getGraphicsConfiguration().createCompatibleImage(w,h);
offG=offImage.createGraphics();
offG.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
//offG.setFont(new Font(offG.getFont().getFontName(),Font.BOLD,12));
}
if(backImage==null)initBackImage(w,h);
offG.drawImage(backImage,0,0,this);
if(pressed){
offG.setColor(pressedColor);
offG.fill(clshape);
}
else{
offG.setColor(pressColor);
offG.fill(clshape);
}
offG.setColor(Color.BLACK);
offG.drawString(getTitle(),8,17);
///////////////////////////////////
myPaint(offG);
paint(g);
}
public void myPaint(Graphics2D g)
{
}
public void paint(Graphics g)
{//绘制
if(offImage==null)
{
repaint();
}
g.drawImage(offImage,0,0,this);
super.paint(g);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -