some general:
GraphingPanel p = new GraphingPanel();
JPanel[] Panel = new JPanel[2];
JLabel[] Label = new JLabel[100];
JTextField[] Field = new JTextField[100];
JButton[] Enter = new JButton[100];
JButton[] Clear = new JButton[100];
JComboBox Subjects = new JComboBox();
JComboBox Topics = new JComboBox();
why do you declare such big fields of components??
Please name them variables starting with lower case, otherwise you will get in trouble with object names.
To your question:
You need to
repaint()
your JPanel.
EDIT:
GraphingPanel oGraphPanel = new GraphingPanel();
JPanel oPanel = new JPanel();
JLabel oLabel = new JLabel();
JTextField oField = new JTextField();
JButton oEnter = new JButton();
JButton oClear = new JButton();
JComboBox oSubjects = new JComboBox();
JComboBox oTopics = new JComboBox();
private void updateGraphPanel(){
if(null != oGraphPanel){
oGraphPanel.setText(oField.getText());
oGraphPanel.repaint();
}
}
public class GraphingPanel extends JPanel
{
private String strText=null;
public void setText(String strText){
this.strText = strText;
}
}
That's about all. the Text is passed to GraphingPanel and then the repaint is triggered.
The text is not yet used there - depends on what you want to do with it. But it's available - so have fun.
-----------------------------------------------------------------------------
EDIT2:
Here is a jump start. compare this to your code (eclipse: right click in Package Explorer -> Compare with...each other).
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
public class GraphingPanel extends JPanel
{
public GraphingPanel()
{
setBounds(50, 50, 500, 400);
setBorder(BorderFactory.createLineBorder(Color.BLACK, 2));
setBackground(Color.WHITE);
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponents(g);
int panelWidth = getWidth();
int panelHeight = getHeight();
g.setColor(Color.WHITE);
g.fillRect(0, 0, panelWidth, panelHeight);
g.setColor(Color.BLACK);
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(1f));
g2.draw(new Line2D.Double( 0, panelHeight/2, panelWidth ,panelHeight/2 ));
g2.draw(new Line2D.Double(panelWidth/2,0, panelWidth/2 ,panelHeight));
g2.setFont(new Font("Times New Roman", Font.PLAIN, 13));
for(int i=1;i<getWidth();i+=9)
{
g2.draw(new Line2D.Double(i, (getHeight()/2)-2, i, (getHeight()/2)+2));
}
for(int i=1;i<getHeight();i+=9)
{
g2.draw(new Line2D.Double((getWidth()/2)-2, i,(getWidth()/2)+2,i));
}
}
public void setValue(int iValue) {
this.repaint();
System.out.println("repainted");
}
}
public class Graphs extends JFrame
{
private GraphingPanel oGraphPanel = new GraphingPanel();
private JPanel oPanel = new JPanel();
private JLabel oLabel = new JLabel();
private JTextField oField = new JTextField();
private JButton oEnter = new JButton();
private JButton oClear = new JButton();
private JComboBox oSubjects = new JComboBox();
private JComboBox oTopics = new JComboBox();
public Graphs()
{
super();
setSize(600, 500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);
loadUI();
}
public void loadUI()
{
oField = new JTextField();
oPanel = new JPanel(null);
oField.setBounds(240, 20, 120, 30);
oField.addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
String strValue = oField.getText();
System.out.println("Enter pressed. Value: " + strValue);
validateIsNumber(strValue);
oGraphPanel.setValue(Integer.parseInt(strValue));
}
}
}
);
oPanel.add(oField);
oPanel.add(oGraphPanel);
add(oPanel);
setVisible(true);
}
private void validateIsNumber(String strValue) {
try{
Integer.parseInt(strValue);
} catch(Exception oException){
JOptionPane.showMessageDialog(this, oException.getLocalizedMessage(),
"oooops", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args)
{
new Graphs();
}
}