标题:为什么不居中阿
取消只看楼主
hellboy
Rank: 1
等 级:新手上路
威 望:1
帖 子:245
专家分:0
注 册:2006-6-24
 问题点数:0 回复次数:1 
为什么不居中阿

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

public class Clock extends JPanel implements ActionListener{
JFrame frame;
int center_X,center_Y;
int r,start_X,start_Y;
public Clock()
{

frame = new JFrame("hellboy clock");
//this.setSize(300,300);
this.setBackground(Color.black);
frame.setBounds(200,200,300,300);
this.init();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(this,"Center");
frame.setVisible(true);
}


public void init()
{
center_X=(int)(frame.getSize().width/2);
center_Y=(int)(frame.getSize().height/2);
System.out.println(center_X+" "+center_Y);
r = (int)(center_X*0.8);
start_X=center_X-r;
start_Y=center_Y-r;
System.out.println(start_X+""+start_Y);

}
public void paint(Graphics g)
{
super.paintComponent(g);
g.drawOval(start_X,start_Y,2*r,2*r);
g.drawRect(start_X,start_Y,2*r,2*r);
g.fillOval(center_X,center_Y,5,5);

}

public void actionPerformed(ActionEvent e)
{

}

public static void main(String[] arg){
new Clock();
}
}

搜索更多相关主题的帖子: public frame import 
2007-03-30 19:57
hellboy
Rank: 1
等 级:新手上路
威 望:1
帖 子:245
专家分:0
注 册:2006-6-24
得分:0 

谢谢 了, 已经搞定


努力 努力 !!!!!!
2007-03-30 23:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-128188-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.438370 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved