import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.awt.geom.*;
class proj extends JFrame implements ChangeListener ,Runnable,ActionListener //main class
{
// Declarations
public int bottom;
public Thread t;
int padding = 4;
JFrame f;
JTabbedPane jt ,jt1;
JPanel jp,jp1,jp2,jp3,jp4;
JButton j,j1,j2;
JLabel lab,lab1;
JComboBox jcb,jcb1;
//public JMenuBar jb;
JMenuItem ji;JMenu jm;
JColorChooser jc,jc1;
Color col1,c2;
public Graphics g;
public Graphics g1;
public Graphics2D g2d;
JDialog dialog;
String k;
Line2D shape1;
// Coding
public void run()
{
f = new JFrame("Graph");
pan jp = new pan();
pan jp1 = new pan(); ;
jt = new JTabbedPane(JTabbedPane.TOP);
jt.setTabPlacement(JTabbedPane.TOP);
//panel1
jp.setPreferredSize(new Dimension (50,50));
jp.setLayout(new BorderLayout());
jp.setBackground(Color.gray);
jp.setPreferredSize(new Dimension(60,50));
jp4 = new JPanel();
j = new JButton("Draw the graph");
j.addActionListener(this);
jp4.setBorder(BorderFactory.createRaisedBevelBorder());
jp4.setPreferredSize(new Dimension(130,20));
jp4.add(j);
jp.add(jp4,BorderLayout.EAST);
String[] a = {"select "};
lab = new JLabel("x parameters");
lab.setLocation(700,700);
jp4.add(lab);
jcb= new JComboBox(a);
jp4.add(jcb);
lab1 = new JLabel("Y parameters");
jp4.add(lab1);
jcb1= new JComboBox(a);
jp4.add(jcb1);
jt.addTab("graph1", jp);
//panel2
jp1.setBackground(Color.black);
jt.addTab("Graph2",jp1);
JPanel jp3=new JPanel();
//Colorchooser
jc = new JColorChooser(Color.yellow);
jc.createDialog(jp3,"Choose Background Color",true, jc, null,null);
jc.getSelectionModel().addChangeListener(this);
jp3.add(jc);
jt.addTab("Change Grid Color", jp3);
f.add(jt);
f.pack();
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
f.setSize(400,400);
f.setVisible(true);
}
public void stateChanged(ChangeEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
if((JButton)e.getSource() == j)
{
/*jc1 = new JColorChooser();
JColorChooser.showDialog(jp4,"Select The Color", Color.red);
c2=jc1.getColor();*/
}
}
//MAIN
public static void main(String[]args)
{
proj lp = new proj();
Thread t = new Thread(lp);
t.start();
}
public class pan extends JPanel
{
Graphics g;
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Color col1=jc.getColor();
g.setColor(col1);
g.drawRect( 30,30,800,600);
for(int i=30;i<=620; i=i+20)
{
g.drawLine(30,i,830,i); // }
g.setColor(Color.white);
for( Integer i=10;i<=620; i=i+20)
{
k=Integer.toString(i);
g.drawString(k,5,i+27);
}
for(Integer i=10;i<=820; i=i+20)
{
int l = i/10;
g.drawString(Integer.toString(l),i+17,650);
}
g.setColor(col1);
for(int i =0;i<=800;i=i+20)
g.drawLine(i+30,30,i+30,630);
}
}
}
This is my proj code...........so my requirement is that when a user presses the button (i.e strat graph) a line shud been plot on the interface.outside pan class am not able to acess g,,,so as to how can i accomplish this........plz reply....help