Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Yes, but he called super.paint(g) so that is good for now until he fixes all the other problems. Then we can nag him about it :P

  2. #22
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

    Default

    ok thanks, im working on it now. I realize im going to have to create my chart in my paintComponent method. The lines work but only visible when I remove my chart and my main black background. Im reading the tutorial once again. thanks

  3. #23
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

    Default

    I'm pretty sure there are still mistakes in my code and I'm sorry for posting so much but I hate to see someone ask the question and find the answer and never post the solution to his/her problem. This is the 3 classes and a screen shot of the program. Thanks a lot for all your help guys.

    TemperaturePanel class:
    Java Code:
    package pr3;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    @SuppressWarnings("serial")
    public class TemperaturePanel extends JComponent {
    	private static double helper = 50;
    	private static double spaceIncrease = 28.57;
    	private static String[] labelNumbers = { "-20", "-10", "0", "10", "20",
    			"30", "40", "50", "60", "70", "80", "90", "100", "110" };
    	private static JPanel[] allNumbers;
    	private static String[] dateNumbers = { "1", "2", "3", "4", "5", "6", "7",
    			"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
    			"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
    			"30", "31" };
    	private static JPanel[] allDates;
    	private static double track = 60;
    	private static double increase = 22;
    
    	public TemperaturePanel() {
    
    		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);
    
    		allNumbers = getNumbers();
    		allDates = getDates();
    
    		for (int i = 0; i < 14; i++) {
    			frame.getContentPane().add(allNumbers[i]);
    
    		}
    
    		for (int i = 0; i < 31; i++) {
    			frame.getContentPane().add(allDates[i]);
    		}
    
    		frame.add(new tester());
    		frame.pack();
    		frame.setVisible(true);
    	}
    
    	private static JPanel[] getNumbers() {
    		JPanel[] ret = new JPanel[14];
    
    		for (int index = 13; index >= 0; index--) {
    			ret[index] = new JPanel();
    			ret[index].setBackground(Color.black);
    			ret[index].setBounds(25, (int) helper, 25, 25);
    			JLabel addMe = new JLabel(labelNumbers[index]);
    			addMe.setForeground(Color.WHITE);
    			ret[index].add(addMe);
    			helper = helper + spaceIncrease;
    		}
    		return ret;
    	}
    
    	private static JPanel[] getDates() {
    		JPanel[] ds = new JPanel[31];
    
    		for (int index = 0; index < 31; index++) {
    			ds[index] = new JPanel();
    			ds[index].setBackground(Color.black);
    			ds[index].setBounds((int) track, 450, 15, 25);
    			JLabel addYou = new JLabel(dateNumbers[index]);
    			addYou.setForeground(Color.white);
    			addYou.setHorizontalTextPosition(JLabel.CENTER);
    			ds[index].add(addYou);
    			track = track + increase;
    		}
    		return ds;
    	}
    
    }
    
    class tester extends JPanel {
    	private int track = 65;
    	private int increase = 22;
    	private double helper = 60;
    	private double spaceIncrease = 28.57;
    
    	public tester() {
    		setBackground(Color.black);
    
    	}
    
    	public Dimension getPreferredSize() {
    		return new Dimension(800, 500);
    	}
    
    	public void paintComponent(Graphics g) {
    		super.paintComponent(g);
    		// g.setColor(Color.CYAN);
    		// g.drawString("Testing 1, 2, 3", 150, 150);
    		g.setColor(Color.white);
    		g.fillRect(50, 50, 690, 400);
    		g.drawString("Temp", 25, 40);
    		g.drawString("Day", 750, 465);
    		g.setColor(Color.black);
    		for (int index = 0; index < 31; index++) {
    			g.drawLine(track, 50, track, 450);
    			track = track + increase;
    		}
    		for (int index = 0; index < 14; index++) {
    			g.drawLine(50, (int) helper, 740, (int) helper);
    			helper = helper + spaceIncrease;
    		}
    	}
    }
    labelPanel class

    Java Code:
    package pr3;
    
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.JPanel;
    
    public class labelPanel extends JPanel {
    
    	public labelPanel() {
    
    		setPreferredSize (new Dimension(800, 500));
    		setBackground	(Color.black);
    	}
    }
    programmain class

    Java Code:
    package pr3;
    
    public class ProgramMain {
    
    	public static void main(String[] args){
    		TemperaturePanel TP = new TemperaturePanel();
    	}
    }
    Once again thank you so much everyone.
    Attached Thumbnails Attached Thumbnails Java GUI drawing a line-rightway.jpg  

  4. #24
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    So do you have any more questions/problems?

  5. #25
    seanfmglobal is offline Member
    Join Date
    Nov 2010
    Posts
    40
    Rep Power
    0

    Default

    No not with this one. Thanks.

  6. #26
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    Glad to help :)

  7. #27
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Drawing coordinates in Java GUI
    By javausr in forum Java 2D
    Replies: 5
    Last Post: 12-29-2010, 10:49 AM
  2. tracing java application line by line using netbeans
    By chandrasekhar123 in forum NetBeans
    Replies: 1
    Last Post: 08-03-2010, 02:46 PM
  3. Replies: 2
    Last Post: 07-02-2010, 02:20 PM
  4. drawing Line by dragging mouse !!!
    By h9h in forum Java 2D
    Replies: 14
    Last Post: 10-23-2009, 05:10 AM
  5. Help with Drawing a line
    By Rgfirefly24 in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •