java的框架尺寸不会弄
importjavax.swing.*;importjava.awt.*;publicclasswanggeextendsJFrame{publicwangge(){ne...
import javax.swing.*;
import java.awt.*;
public class wangge extends JFrame
{
public wangge()
{
newlabel a=new newlabel();
add(a);
}
public static void main(String[] args)
{
wangge zx=new wangge();
zx.setTitle("testwangge");
zx.setLocationRelativeTo(null);
zx.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
zx.setSize(150,150);
zx.setVisible(true);
}
}
class newlabel extends JLabel
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawLine(0,50,150,50);
g.drawLine(0,100,150,100);
g.setColor(Color.RED);
g.drawLine(50,0,50,150);
g.drawLine(100,0,100,150);
}
}
按道理框架应该是(150,150),但是我的线是按1/3的比例画的网格,应该出现的是成比例的,为什么一开始显示就是不对的呢,请教高手! 展开
import java.awt.*;
public class wangge extends JFrame
{
public wangge()
{
newlabel a=new newlabel();
add(a);
}
public static void main(String[] args)
{
wangge zx=new wangge();
zx.setTitle("testwangge");
zx.setLocationRelativeTo(null);
zx.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
zx.setSize(150,150);
zx.setVisible(true);
}
}
class newlabel extends JLabel
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawLine(0,50,150,50);
g.drawLine(0,100,150,100);
g.setColor(Color.RED);
g.drawLine(50,0,50,150);
g.drawLine(100,0,100,150);
}
}
按道理框架应该是(150,150),但是我的线是按1/3的比例画的网格,应该出现的是成比例的,为什么一开始显示就是不对的呢,请教高手! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询