方法调用的问题

青葱少年 2017-02-20 04:48:25
我的这个画线调用一直是错的 请问怎么改

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class qwe{
public static void main(String[]args){
ButtonDemo myButtonGUI=new ButtonDemo();
myButtonGUI.setVisible(true);
}
}
@SuppressWarnings("serial")
class ButtonDemo extends JFrame implements ActionListener{
public static final int Width=700;
public static final int Height=500;
ButtonDemo(){
setSize(Width,Height); setTitle("股市随机生成走势图");
Container conPane=getContentPane();
conPane.setBackground(Color.BLACK);
conPane.setLayout(new FlowLayout());
JButton redBut=new JButton("百度");
redBut.addActionListener(this);
conPane.add(redBut);
JButton greenBut=new JButton("谷歌");
greenBut.addActionListener(this);
conPane.add(greenBut);
}
public void actionPerformed(ActionEvent e){
Container conPane=getContentPane();
if(e.getActionCommand().equals("百度"))
{draw(g);}
//conPane.setBackground(Color.GREEN);
else if(e.getActionCommand().equals("谷歌"))
{draw(g);}
else{}
}

public void paint(Graphics g)
{
int y1=500,y2;
g.setColor(Color.BLUE);
for(int j=1;j<=10;j++)
{
y2=(int) (Math.random()*700);
g.drawLine((j-1)*50,y1,j*50, y2);
y1=y2;
}

}
}
...全文
197 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
把分全给哥 2017-02-22
  • 打赏
  • 举报
回复
jiajing1990_ 2017-02-22
  • 打赏
  • 举报
回复
引用 5 楼 ryuugu_rena 的回复:
g这个变量找不到,你没在类里面声明。
+1
  • 打赏
  • 举报
回复
引用 5 楼 ryuugu_rena 的回复:
g这个变量找不到,你没在类里面声明。
+1
ryuugu_rena 2017-02-20
  • 打赏
  • 举报
回复
g这个变量找不到,你没在类里面声明。
青葱少年 2017-02-20
  • 打赏
  • 举报
回复
引用 3 楼 ryuugu_rena 的回复:
把运行的错误贴出来!


这个么?
还是控制台的?
ryuugu_rena 2017-02-20
  • 打赏
  • 举报
回复
把运行的错误贴出来!
青葱少年 2017-02-20
  • 打赏
  • 举报
回复
引用 1 楼 qnmdcsdn 的回复:
说明一下是哪种错。程序报错贴错误,逻辑不对讲逻辑
应该是逻辑不对吧 就是draw(g); 这个画线方法引用不了
  • 打赏
  • 举报
回复
说明一下是哪种错。程序报错贴错误,逻辑不对讲逻辑

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧