📄 frmsetup.java
字号:
package bin;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
public class FrmSetup extends JDialog implements Runnable
{
public FrmSetup(JFrame owner)
{
super(owner, "ButtonSetup ", true);
setSize(196, 220);
this.setLayout(null);
Icon imgButton=new ImageIcon("image\\setup.gif");
final JButton button=new JButton("关闭");
button.setFont(new Font("",Font.BOLD,10));
button.setForeground(Color.WHITE);
button.setFocusable(false);
button.setBounds(25,197,150,12);
button.setBackground(Color.BLACK);
button.setForeground(Color.CYAN);
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e) {
setVisible(false);
}
public void mouseEntered(MouseEvent e)
{
button.setForeground(Color.WHITE);
}
public void mouseExited(MouseEvent e)
{
button.setForeground(Color.CYAN);
}
});
SetupUp setup = new SetupUp();
setup.setBounds(30,38,150,15);
SetDown setdown = new SetDown();
setdown.setBounds(30,58,150,15);
SetLeft setleft = new SetLeft();
setleft.setBounds(30,78,150,15);
SetRight setright = new SetRight();
setright.setBounds(30,98,150,15);
LeftPit leftpit = new LeftPit();
leftpit.setBounds(30,118,150,15);
RightPit rightpit = new RightPit();
rightpit.setBounds(30,138,150,15);
OkReset okreset = new OkReset(setup,setdown,setleft,setright,leftpit,rightpit);//构造方法的参数传递
okreset.setBounds(30,165,150,15);
this.add(setup);
this.add(setdown);
this.add(setleft);
this.add(setright);
this.add(leftpit);
this.add(rightpit);
this.add(okreset);
this.add(button);
this.setUndecorated(true);
setupPanel pane = new setupPanel();//实例面板类对象
pane.setBounds(0,0,196,220);//起始坐标和面板的大小//设置图片位置和大小
add(pane);
fx=owner.getX ()+20;//获得当前主窗体的X坐标
fy=owner.getY()+10;
x=((fx+owner.getWidth())-220);//获得主窗体的宽度减去小窗体的宽度 就获得了固定出现的位置(在主窗体内)
y=(fy-this.getHeight());//获得大窗体的高度减去获得当前小窗体的高度 为了使小窗体完全进入大窗体
this.setLocation(x,y);///设置小窗体的位置
t=new Thread(this);//创建一个线程
t.start();//启动线程
}
public void run()//启动线程总是调用run()方法
{
for(int i=y;i<=fy;i=i+30)// i是小窗体在大窗体内部的坐标 fy是大窗体的边框坐标 当i的坐标 小于大窗体内部的坐标时开始循环每次递增50的y坐标一直到小窗体完全进入后停止
{
this.setLocation(x,i);//按照循环的位置来递增小窗体的y坐标 x坐标的位置不变
try {
t.sleep(1);//将线程休眠1毫秒
} catch (InterruptedException e1)
{
e1.printStackTrace();
}
}
}
private Thread t;//线程类型的变量
private int x;
private int y;
private int fy;
private int fx;
}
class setupPanel extends JPanel{
public setupPanel()
{
try
{
setup=ImageIO.read(new File("image\\setup.gif"));//小面板的底层画面
}
catch(IOException exception)
{
exception.printStackTrace();
}
}
public void paint(Graphics g)
{
super.paint(g);
g.drawImage(setup,0,0,null);//将图画画到面板上去
}
private Image setup;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -