小程序都出错,为啥啊?求指教
java吧
全部回复
仅看楼主
level 3
zbbb306 楼主
//DrawPanel.java
import java.awt.Graphics;
import javax.swing.JPanel;
import java.awt.Color;
public class DrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int width=getWidth();
int height=getHeight();
g.setColor(Color.red);
g.drawLine(0,0,width,height);
g.drawLine(0,height,width,0);
}
}
//TestDrawLine.java
import javax.swing.JFrame;
public class TestDrawLine
{
public static void main(String args[])
{
DrawPanel myPanel=new DrawPanel();
JFrame myWindow=new JFrame();
myWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myWindow.add(myPanel);
myWindow.setSize(300,500);
myWindow.setVisible(true);
}
}
2014年03月19日 04点03分 1
level 3
zbbb306 楼主
别沉啊
2014年03月19日 04点03分 2
level 3
zbbb306 楼主
木有人么?
2014年03月19日 05点03分 3
level 3
zbbb306 楼主
救命啊
2014年03月19日 05点03分 4
level 12
你两个public class放一起编译了吧
2014年03月19日 05点03分 5
谢谢 我试试
2014年03月19日 06点03分
level 9
必须两个把java文件(实际上是class文件)放在同一个路径下面
2014年03月19日 06点03分 6
level 9
2014年03月19日 06点03分 7
level 9
2014年03月19日 06点03分 8
[大拇指]
2014年03月19日 08点03分
level 5
import javax.swing.JFrame;
2014年03月19日 08点03分 9
1