Hello everyone. I have been trying to figure this out for a long time and can't seem to get it right. I am trying to create lines for my graph and I was going by using paint component.
But no matter what the line will not be drawn. Here is the code that I am working with.Code:public void paint(Graphics g){
drawLine(x1, y1, x2, y2);
}
Code:package pr3;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TemperaturePanel{
public static void main(String[] args) {
JFrame frame = new JFrame ("Project 3 by C. Ross: Highs and lows with predictions one day in advance for March, 2011");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
labelPanel mainPan = new labelPanel();
/*
* creation of all the panels for all the texts
*/
JPanel chart = new JPanel();
JPanel negT = new JPanel();
JPanel negTn = new JPanel();
JPanel zero = new JPanel();
JPanel ten = new JPanel();
JPanel twenty = new JPanel();
JPanel thirty = new JPanel();
JPanel fourty = new JPanel();
JPanel fifty = new JPanel();
JPanel sixty = new JPanel();
JPanel seventy = new JPanel();
JPanel eighty = new JPanel();
JPanel ninty = new JPanel();
JPanel hundred = new JPanel();
JPanel hundredTen = new JPanel();
/*
* Setting the panel up: background, location, label, label color, and adding the label to the panel
*
* Negative 20
*/
negT.setBackground(Color.black);
negT.setBounds(25, 420, 25, 25);
JLabel tester = new JLabel ("-20");
tester.setForeground(Color.white);
negT.add(tester);
/*
* Negative 10
*/
negTn.setBackground(Color.black);
negTn.setBounds(25, 400, 25, 25);
JLabel negTenLabel = new JLabel("-10");
negTenLabel.setForeground(Color.white);
negTn.add(negTenLabel);
/*
* zero
*/
zero.setBackground(Color.black);
zero.setBounds(25, 380, 25, 25);
JLabel zeroLabel = new JLabel("0");
zeroLabel.setForeground(Color.white);
zero.add(zeroLabel);
/*
* ten
*/
ten.setBackground(Color.black);
ten.setBounds(25, 360, 25, 25);
JLabel tenLabel = new JLabel("10");
tenLabel.setForeground(Color.white);
ten.add(tenLabel);
/*
* twenty
*/
twenty.setBackground(Color.black);
twenty.setBounds(25, 340, 25, 25);
JLabel twentyLabel = new JLabel("20");
twentyLabel.setForeground(Color.white);
twenty.add(twentyLabel);
/*
* thirty
*/
thirty.setBackground(Color.black);
thirty.setBounds(25, 320, 25, 25);
JLabel thirtyLabel = new JLabel("30");
thirtyLabel.setForeground(Color.white);
thirty.add(thirtyLabel);
/*
* fourty
*/
fourty.setBackground(Color.black);
fourty.setBounds(25, 300, 25, 25);
JLabel fourtyLabel = new JLabel("40");
fourtyLabel.setForeground(Color.white);
fourty.add(fourtyLabel);
/*
* fifty
*/
fifty.setBackground(Color.black);
fifty.setBounds(25, 280, 25, 25);
JLabel fiftyLabel = new JLabel("50");
fiftyLabel.setForeground(Color.white);
fifty.add(fiftyLabel);
/*
* sixty
*/
sixty.setBackground(Color.black);
sixty.setBounds(25, 260, 25, 25);
JLabel sixtyLabel = new JLabel("60");
sixtyLabel.setForeground(Color.white);
sixty.add(sixtyLabel);
/*
* seventy
*/
seventy.setBackground(Color.black);
seventy.setBounds(25, 240, 25, 25);
JLabel seventyLabel = new JLabel("70");
seventyLabel.setForeground(Color.white);
seventy.add(seventyLabel);
/*
* eighty
*/
eighty.setBackground(Color.black);
eighty.setBounds(25, 220, 25, 25);
JLabel eightyLabel = new JLabel("80");
eightyLabel.setForeground(Color.white);
eighty.add(eightyLabel);
/*
* ninty
*/
ninty.setBackground(Color.black);
ninty.setBounds(25, 200, 25, 25);
JLabel nintyLabel = new JLabel("90");
nintyLabel.setForeground(Color.white);
ninty.add(nintyLabel);
/*
* hundred
*/
hundred.setBackground(Color.black);
hundred.setBounds(25, 180, 25, 25);
JLabel hundredLabel = new JLabel("100");
hundredLabel.setForeground(Color.white);
hundred.add(hundredLabel);
/*
* hundredTen
*/
hundredTen.setBackground(Color.black);
hundredTen.setBounds(25, 160, 25, 25);
JLabel hundredTenLabel = new JLabel("110");
hundredTenLabel.setForeground(Color.white);
hundredTen.add(hundredTenLabel);
/*
* Whitespace for the graph
*/
chart.setBounds(50, 50, 690, 400);
chart.setBackground(Color.white);
/*
* Adding everything to the frame
*/
frame.getContentPane().add(negT);
frame.getContentPane().add(negTn);
frame.getContentPane().add(zero);
frame.getContentPane().add(ten);
frame.getContentPane().add(twenty);
frame.getContentPane().add(thirty);
frame.getContentPane().add(fourty);
frame.getContentPane().add(fifty);
frame.getContentPane().add(sixty);
frame.getContentPane().add(seventy);
frame.getContentPane().add(eighty);
frame.getContentPane().add(ninty);
frame.getContentPane().add(hundred);
frame.getContentPane().add(hundredTen);
frame.getContentPane().add(chart);
frame.getContentPane().add(mainPan);
frame.pack();
frame.setVisible(true);
}
public void paint(Graphics g){
g.drawLine(50, 50, 300, 300);
g.setColor(Color.yellow);
}
}

