hi all,
i'm getting 2 cannot resolve symbol errors after i compiled my code. the full description of the errors are as below:
1. cannot resolve symbol
symbol: method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData(""));
^
2. cannot resolve symbol
symbol : method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData
(materialx.getSelectedItem().toString()));
^
i have a shorter version of this code & it worked. after i made some modifications like adding another jbutton & jcombobox then i started getting these errors. i must have made a few errors but unfortunately i just cannot figure out where i went wrong.
i would really appreciate if any of you guys can help me on this. thanks in advance.
below is my code:
i'm getting 2 cannot resolve symbol errors after i compiled my code. the full description of the errors are as below:
1. cannot resolve symbol
symbol: method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData(""));
^
2. cannot resolve symbol
symbol : method addData (MyData)
location: class javax.swing.JPanel
centerPanel.addData(new MyData
(materialx.getSelectedItem().toString()));
^
i have a shorter version of this code & it worked. after i made some modifications like adding another jbutton & jcombobox then i started getting these errors. i must have made a few errors but unfortunately i just cannot figure out where i went wrong.
i would really appreciate if any of you guys can help me on this. thanks in advance.
below is my code:
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics2D;
import java.awt.Graphics.*;
import java.util.ArrayList;
public class Testing extends JFrame implements ActionListener
{
String x[] = { " ", "Material A", "Material B", "Material C"};
String y[] = { " ", "+5", "+4", "+3", "+2", "+1", " 0", "-1", "-2", "-3", "-2", "-5" };
private JButton Plot, End;
private Container c;
private JPanel centerPanel, northPanel, southPanel;
private JComboBox materialx, materialRatingy;
MyGraph mg = new MyGraph();
public Testing()
{
super( "Welcome" );
Container c = getContentPane();
centerPanel.addData(new MyData(""));
centerPanel = new JPanel();
centerPanel.setBackground(Color.white);
c.add( centerPanel, BorderLayout.CENTER);
setVisible(true);
northPanel = new JPanel();
northPanel.add(new Label( "Please choose accordingly:" ));
northPanel.setLayout (new FlowLayout(FlowLayout.CENTER, 20, 0));
materialx = new JComboBox( x );
materialx.setMaximumRowCount( 2 );
materialx.setBorder
(BorderFactory.createTitledBorder("Design Materials"));
northPanel.add( materialx );
materialx.setEditable(true);
materialRatingy = new JComboBox( y );
materialRatingy.setMaximumRowCount( 2 );
materialRatingy.setBorder(BorderFactory.createTitledBorder("Material Ratings"));
northPanel.add( materialRatingy );
c.add( northPanel, BorderLayout.NORTH );
setVisible( true );
southPanel = new JPanel();
Plot = new JButton( "Plot" );
End = new JButton( "End" );
southPanel.add( Plot );
southPanel.add( End );
c.add( southPanel, BorderLayout.SOUTH );
setVisible( true );
Plot.addActionListener(this);
End.addActionListener(this);
Plot.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
centerPanel.addData(new MyData(materialx.getSelectedItem().toString()));
centerPanel.repaint();
}
});
pack();
}
public static void main( String args[] )
{
Testing app = new Testing();
app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Plot)
{
System.out.println("Plot");
}
else if(e.getSource()==End)
{
System.exit(0);
}
}
}
class MyGraph extends JPanel
{
ArrayList al = new ArrayList();
public void addData(MyData data)
{ al.add(data); }
public void paintComponent(Graphics g)
{
Graphics2D g2d = (Graphics2D)g;
super.paintComponent(g);
for (int i=0; i<al.size(); i++)
{
MyData md = (MyData)al.get(i);
g.setColor(Color.blue);
g.drawRect(120+i*20, 120, 20, 200);
g.drawString ("Material", 30, 220);
g.drawString ("Ratings", 30, 240);
g.drawString ("+5", 102, 130);
g.drawString ("0", 107, 220);
g.drawString ("-5", 102, 315);
g.setColor(Color.red);
g.drawRect(120+i*20, 321, 20, 200);
g.drawString ("Design", 30, 410);
g.drawString ("Materials", 30, 430);
}
g2d.rotate(-Math.PI/2.0,250,250);
g.setColor(Color.blue);
for (int i=0; i<al.size(); i++)
{
MyData md = (MyData)al.get(i);
g2d.drawString(md.getMaterial(),-15,15+i*20);
}
}
}
class MyData {
String material;
public MyData(String material) {
this.material=material;
}
public String getMaterial() { return material; }
}