62,614
社区成员
发帖
与我相关
我的任务
分享
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.RED);
g.drawString("hello java", x,y);
}
public void ac(){
paint(Graphics g);
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class lcd extends JFrame{
JPanel p = new JPanel();
private JButton b1 = new JButton("Setup");
private JButton b2 = new JButton("Hide");
private Image icon;
// Thread t1 = new Thread(new t1(this));
private int x=0;
private int y=40;
Graphics gg;
public lcd(){
icon=Toolkit.getDefaultToolkit().getImage("1.gif");
Container con = this.getContentPane();
con.setLayout(null);
b1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
b1_button(e);
}
});
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b2_button(e);
}
});
p.setBackground(Color.BLACK);
p.setBounds(0, 85, 400, 50);
b1.setBounds(340, 0, 60, 40);
b1.setBackground(Color.BLACK);
b1.setForeground(Color.WHITE);
b1.setBorder(null);
b2.setBounds(280, 0, 60, 40);
b2.setBackground(Color.BLACK);
b2.setForeground(Color.WHITE);
b2.setBorder(null);
p.add(b2);
p.setLayout(null);
p.add(b1);
con.add(p);
con.setBackground(Color.WHITE);
// this.setIconImage(icon)
}
public void paint(Graphics g){
super.paint(g);
g.setColor(Color.RED);
g.drawString("hello java", x,y);
}
public void ac(){
paint(Graphics g);
}
public void b1_button(ActionEvent e){
lcdcomset lc = new lcdcomset();
lc.setVisible(true);
}
public void b2_button(ActionEvent e){
ac();
}
public static void main(String args[]){
lcd lc= new lcd();
lc.setSize(400,150);
int windowWidth = lc.getWidth(); //获得窗口宽
int windowHeight = lc.getHeight(); //获得窗口高
Toolkit kit = Toolkit.getDefaultToolkit(); //定义工具包
Dimension screenSize = kit.getScreenSize(); //获取屏幕的尺寸
int screenWidth = screenSize.width; //获取屏幕的宽
int screenHeight = screenSize.height; //获取屏幕的高
lc.setLocation(screenWidth/2-windowWidth/2, screenHeight/2-windowHeight/2);
lc.setVisible(true);
}
}
public static void paint(Graphics g){
super.paint(g);
g.setColor(Color.RED);
g.drawString("hello java", x,y);
}
public void ac(){
paint(Graphics g);
}