Dot chart in Java
Class No:1
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class Main extends JFrame {
private Mypanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Main frame = new Main();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(200, 200, 800, 800);
contentPane = new Mypanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
Class No:2
import java.awt.Graphics;
import javax.swing.JPanel;
import java.awt.Color;
public class Mypanel extends JPanel {
public Mypanel() {
setForeground(new Color(0, 0, 0));
setBackground(new Color(220, 20, 60));
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
for(int h=0; h <= 800; h = h + 50)
g.drawLine(0, h, 800, h);
for(int h=0; h <=800; h = h + 50)
g.drawLine(h,0,h,800);
for(int i=10; i < 800; i = i + 50){
g.setColor(Color.BLACK);
//with loop
for (int c = 10; c<800 ; c=c+50) {
g.fillArc(i,c,35,35, 0, 360);
}
//hard coded
// g.fillArc(i,10,35,35, 0, 360);
// g.fillArc(i,60,35,35, 0, 360);
// g.fillArc(i,110,35,35, 0, 360);
// g.fillArc(i,160,35,35, 0, 360);
// g.fillArc(i,210,35,35, 0, 360);
// g.fillArc(i,260,35,35, 0, 360);
// g.fillArc(i,310,35,35, 0, 360);
// g.fillArc(i,360,35,35, 0, 360);
// g.fillArc(i,410,35,35, 0, 360);
// g.fillArc(i,460,35,35, 0, 360);
// g.fillArc(i,510,35,35, 0, 360);
// g.fillArc(i,560,35,35, 0, 360);
// g.fillArc(i,610,35,35, 0, 360);
// g.fillArc(i,660,35,35, 0, 360);
// g.fillArc(i,710,35,35, 0, 360);
// g.fillArc(i,760,35,35, 0, 360);
}
}
}
Comments
Post a Comment