java怎么画出一个圆形,我这个为什么画不了呀?
publicclassFirstJFrameextendsCanvasimplementsActionListener{inta=0;intb=0;intc=0;intc...
public class FirstJFrame extends Canvas implements ActionListener {
int a = 0;
int b = 0;
int c = 0;
int c1 = 0 ;
int d = 0;
JFrame jf = new JFrame();
Canvas yb = new Canvas();
JMenuBar bar = new JMenuBar();
JMenu menu_xuanze = new JMenu("选择图形");
JMenu menu_yuanyu = new JMenu("关于");
JMenuItem yuan = new JMenuItem("圆形");
JMenuItem juxing = new JMenuItem("矩形");
JMenuItem sanjiao = new JMenuItem("三角形");
public static void main(String[] args) {
new FirstJFrame().createUI();
}
public void createUI(){
bar.setBackground(Color.LIGHT_GRAY);
bar.add(menu_xuanze);
bar.add(menu_yuanyu);
menu_xuanze.add(yuan);
menu_xuanze.add(juxing);
menu_xuanze.add(sanjiao);
yuan.addActionListener(this);
jf.setJMenuBar(bar);
jf.add(yb);
jf.setSize(400, 300);
jf.setLocation(400, 200);
yb.setVisible(true);
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s = e.getActionCommand();
if(s.equals("圆形")){
YJFrame frame = new YJFrame();
frame.creatUI();
c1 = frame.dedao();
update();
}
}
public void update(){
System.out.println("ssssss");
repaint();
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
System.out.println("--"+c1);
g.drawOval(400, 200, c1,c1);
}
}
我想在我输入半径之前Canvas是空白的。YJFrame只是一个新的可以获取半径的jframe,我这样写为什么画不出来圆啊?? 展开
int a = 0;
int b = 0;
int c = 0;
int c1 = 0 ;
int d = 0;
JFrame jf = new JFrame();
Canvas yb = new Canvas();
JMenuBar bar = new JMenuBar();
JMenu menu_xuanze = new JMenu("选择图形");
JMenu menu_yuanyu = new JMenu("关于");
JMenuItem yuan = new JMenuItem("圆形");
JMenuItem juxing = new JMenuItem("矩形");
JMenuItem sanjiao = new JMenuItem("三角形");
public static void main(String[] args) {
new FirstJFrame().createUI();
}
public void createUI(){
bar.setBackground(Color.LIGHT_GRAY);
bar.add(menu_xuanze);
bar.add(menu_yuanyu);
menu_xuanze.add(yuan);
menu_xuanze.add(juxing);
menu_xuanze.add(sanjiao);
yuan.addActionListener(this);
jf.setJMenuBar(bar);
jf.add(yb);
jf.setSize(400, 300);
jf.setLocation(400, 200);
yb.setVisible(true);
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s = e.getActionCommand();
if(s.equals("圆形")){
YJFrame frame = new YJFrame();
frame.creatUI();
c1 = frame.dedao();
update();
}
}
public void update(){
System.out.println("ssssss");
repaint();
}
@Override
public void paint(Graphics g) {
// TODO Auto-generated method stub
super.paint(g);
System.out.println("--"+c1);
g.drawOval(400, 200, c1,c1);
}
}
我想在我输入半径之前Canvas是空白的。YJFrame只是一个新的可以获取半径的jframe,我这样写为什么画不出来圆啊?? 展开
1个回答
2015-05-24
展开全部
YJFrame frame = new YJFrame();
frame.creatUI();
c1 = frame.dedao();
update();
每次都是新建的呀,显示了吗
frame.creatUI();
c1 = frame.dedao();
update();
每次都是新建的呀,显示了吗
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询