11 个解决方案
#1
画坐标不行了 g2.drawLine(x,y,z,w)
#2
drawLine(x1,y1,x2,y2)这样画出来的是一个象素的,请问如何能画出2个象素的?
#3
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class T
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new JPanel() {
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(10, 10, 200, 250);
}
}, BorderLayout.CENTER);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
import javax.swing.JFrame;
import javax.swing.JPanel;
public class T
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new JPanel() {
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(10, 10, 200, 250);
}
}, BorderLayout.CENTER);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
#4
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
((Graphics2D)g).setStroke(stroke);
#5
两位兄弟的方法不错,但如果要求在jdk1.1这前的版本,应该用什么方法呢??在JDK1.1中没有Graphics2D
#6
难道真得没办法吗??
#7
大家说的对,就
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
#8
//未经测试
g.drawLine(x1,y1,x2,y2);
g.drawLine(x1,y1-1,x2;y2-1);
g.drawLine(x1,y1,x2,y2);
g.drawLine(x1,y1-1,x2;y2-1);
#9
chuan122345,你的方法在JDK1.1行不通,因为没有Graphics2D这个类,
redduke1202,你说的方法只能画出一个象素粗的线,在JDK1.1如何能画两个象素的呢?
redduke1202,你说的方法只能画出一个象素粗的线,在JDK1.1如何能画两个象素的呢?
#10
JDK1.1只能自己实现线宽,比如用一系列小矩形等等,但效率很低
#11
如果是这样的话,那Graphics2D这个类又是如何实现的呢?可以自己模仿它来实现呢?请高人指点
#1
画坐标不行了 g2.drawLine(x,y,z,w)
#2
drawLine(x1,y1,x2,y2)这样画出来的是一个象素的,请问如何能画出2个象素的?
#3
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class T
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new JPanel() {
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(10, 10, 200, 250);
}
}, BorderLayout.CENTER);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
import javax.swing.JFrame;
import javax.swing.JPanel;
public class T
{
public static void main(String[] args)
{
JFrame f = new JFrame();
f.getContentPane().add(new JPanel() {
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setStroke(new BasicStroke(2));
g2d.drawLine(10, 10, 200, 250);
}
}, BorderLayout.CENTER);
f.setSize(300, 300);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
#4
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
((Graphics2D)g).setStroke(stroke);
#5
两位兄弟的方法不错,但如果要求在jdk1.1这前的版本,应该用什么方法呢??在JDK1.1中没有Graphics2D
#6
难道真得没办法吗??
#7
大家说的对,就
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
Stroke stroke = new BasicStroke( int width);
((Graphics2D)g).setStroke(stroke);
#8
//未经测试
g.drawLine(x1,y1,x2,y2);
g.drawLine(x1,y1-1,x2;y2-1);
g.drawLine(x1,y1,x2,y2);
g.drawLine(x1,y1-1,x2;y2-1);
#9
chuan122345,你的方法在JDK1.1行不通,因为没有Graphics2D这个类,
redduke1202,你说的方法只能画出一个象素粗的线,在JDK1.1如何能画两个象素的呢?
redduke1202,你说的方法只能画出一个象素粗的线,在JDK1.1如何能画两个象素的呢?
#10
JDK1.1只能自己实现线宽,比如用一系列小矩形等等,但效率很低
#11
如果是这样的话,那Graphics2D这个类又是如何实现的呢?可以自己模仿它来实现呢?请高人指点