java中graphics类划线的问题
publicclasstestframeextendsJFrame{/***@paramargsthecommandlinearguments*/publicstatic...
public class testframe extends JFrame{
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
JPanel p=new JPanel();
frame.getContentPane().add(p);
graphics g = new graphics();
p.add(g);
// TODO code application logic here
}
}
class graphics extends JPanel{
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawLine(0, 0, 0, 120);
g.setColor(Color.GREEN);
}
}
为什么无论怎么调g.drawLine()中的数 画出来的线总是很短
希望能在原有的程序上进行修改 展开
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
JPanel p=new JPanel();
frame.getContentPane().add(p);
graphics g = new graphics();
p.add(g);
// TODO code application logic here
}
}
class graphics extends JPanel{
protected void paintComponent(Graphics g){
super.paintComponent(g);
g.drawLine(0, 0, 0, 120);
g.setColor(Color.GREEN);
}
}
为什么无论怎么调g.drawLine()中的数 画出来的线总是很短
希望能在原有的程序上进行修改 展开
2个回答
展开全部
class testframe extends JFrame {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setContentPane(new graphics());
}
}
class graphics extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(0, 0, 120, 120);
g.setColor(Color.GREEN);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
frame.setContentPane(new graphics());
}
}
class graphics extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(0, 0, 120, 120);
g.setColor(Color.GREEN);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询