package carspeedometer;
import java.awt.Graphics;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
class a1 {
a1() {
JFrame jf = new JFrame("Speedometer");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel jp = new JPanel();
JLabel jb = new JLabel(new ImageIcon(
"C:/Users/Vinayak/Desktop/tester.jpg"));
jp.add(jb);
jf.add(jp);
jf.setVisible(true);
jf.setSize(700, 700);
}
public void paint(Graphics g) {
g.drawLine(70, 70, 200, 200);
}
public static void main(String...s) {
new a1();
}
}
Line is not showing on screen.I want to show line on top of the image.please help. Here i am trying to build a speedometer but first a line needs to be displayed
You can only draw in Swing if you override a drawing method of a component. Here your paint method overrides nothing because your class extends nothing. I suggest
paintComponent(Graphics g)
method @Override
annotation to verify the override
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.