当前位置: 技术问答>java相关
给我指迷津,谢谢了,关于方法调用问题
来源: 互联网 发布时间:2017-04-30
本文导语: 我在LabelPanel.java中调用另一个drawline.java中的paint方法怎么老是出错,我不知道什么原因,请帮忙解决,谢谢先! import javax.swing.*; import java.awt.event.*; import java.awt.*; public class LabelPanel extends JPanel { public LabelPanel...
我在LabelPanel.java中调用另一个drawline.java中的paint方法怎么老是出错,我不知道什么原因,请帮忙解决,谢谢先!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class LabelPanel extends JPanel
{
public LabelPanel()
{
add(new JLabel("hello,i am just label"));
}
Graphics g;
drawline draw=new drawline();
draw.paint(g);
}
////////////////////////
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class drawline extends JFrame
{
Color color1=new Color(255,0,0);
Color color2=new Color(0,255,0);
Color color3=new Color(0,0,255);
public void drawline()
{
}
public void paint(Graphics g)
{
int x1=50; // X 轴图标之间的宽度
int y1=50; // Y 轴图标之间的宽度
int w=20; //条形的宽度
int x2=500;
int y2=500;
g.setColor(new Color(200));
String msg="折线";
g.drawString(msg,200,30);
g.setColor(new Color(50,100,60)); // 画坐标 x,y轴的坐标
g.drawLine(50,50,50,y2);// Y 轴
g.drawLine(50,y2,x2,y2);// X 轴
g.drawLine(40,60,50,50); //箭头
g.drawLine(50,50,60,60);
g.drawLine(490,490,x2,y2);
g.drawLine(x2,y2,490,510);
//////图标尺寸 y 轴
g.setColor(Color.blue);
g.drawString("单位:(人)",35,40);
for(int i=0;i
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class LabelPanel extends JPanel
{
public LabelPanel()
{
add(new JLabel("hello,i am just label"));
}
Graphics g;
drawline draw=new drawline();
draw.paint(g);
}
////////////////////////
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class drawline extends JFrame
{
Color color1=new Color(255,0,0);
Color color2=new Color(0,255,0);
Color color3=new Color(0,0,255);
public void drawline()
{
}
public void paint(Graphics g)
{
int x1=50; // X 轴图标之间的宽度
int y1=50; // Y 轴图标之间的宽度
int w=20; //条形的宽度
int x2=500;
int y2=500;
g.setColor(new Color(200));
String msg="折线";
g.drawString(msg,200,30);
g.setColor(new Color(50,100,60)); // 画坐标 x,y轴的坐标
g.drawLine(50,50,50,y2);// Y 轴
g.drawLine(50,y2,x2,y2);// X 轴
g.drawLine(40,60,50,50); //箭头
g.drawLine(50,50,60,60);
g.drawLine(490,490,x2,y2);
g.drawLine(x2,y2,490,510);
//////图标尺寸 y 轴
g.setColor(Color.blue);
g.drawString("单位:(人)",35,40);
for(int i=0;i