Tue Mar 18, 2008 11:36 pm
package xycurve;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class myPanel extends JPanel implements ChangeListener{
/** Creates a new instance of myPanel */
private JButton randButton=new JButton("Draw");
private JSlider brislide=new JSlider(0,255,128);
private JTextField myText=new JTextField(3);
private JLabel myLabel=new JLabel("Max Temperature ");
private int[] temparray=new int[]{7,10,25,50,30};
private float[] timearray=new float[] {8.15f, 8.45f, 9.15f, 9.45f, 10.15f};
private int oldy;
public myPanel() {
randButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
}
});
brislide.addChangeListener(this);
add(randButton);
add(brislide);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(10,300,10,200);
g.drawLine(10,300,110,300);
g.setColor(Color.BLUE);
oldy=0;
for(int i=0;i<timearray.length*20;i+=20) {
g.drawLine(30+i-20,300-oldy,30+i,300-temparray[i/20]);
oldy=temparray[i/20];
g.setColor(Color.RED.brighter());
g.drawOval(30+i-2,300-temparray[i/20]-2,4,4);
g.setColor(Color.BLUE);
}
g.setColor(Color.RED);
g.drawString("Temperature",10,100);
g.drawString("Time ",120,300);
}
public void stateChanged(ChangeEvent e) {
/// Called when You change the Slider Value
System.out.println(brislide.getValue());
}
}
Sat Dec 10, 2011 7:53 am
Sun Jan 20, 2013 5:35 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.