Can you increase the line thickness when using Java Graphics for an applet? I don't think BasicStroke works

I'm having trouble adjusting the line thickness. Can I do this in Graphics or do I need to do this in Graphics2D? If so, how do I change the program so that it runs?

Thanks!

import java.applet.Applet; import java.awt.*; public class myAppletNumberOne extends Applet { public void paint (Graphics page) { //Something here??? } } 
+7
source share
1 answer

Yes, you should do it in Graphics2D, but this is hardly a problem, since every graphic in Swing is a Graphics2D object (it just keeps the old interface for compatibility reasons).

 public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setStroke(new BasicStroke(3)); g2.drawLine(...); //thick ... } 

As you can see, g2.setStroke (...) allows you to change the course and even BasicStroke, which provides an easy choice of line width.

+21
source

All Articles