Fri May 18, 2007 2:09 pm
/*
* myFrame.java
*/
import javax.swing.JFrame;
public class myFrame extends JFrame{
public myFrame() {
getContentPane().add(cpanel);
setTitle("XY-Curve");
setSize(600,450);
setLocation(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new myFrame();
}
myPanel cpanel=new myPanel();
}
/*
* myPanel.java
*/
import java.awt.*;
import java.awt.geom.*;
import java.awt.Color;
import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JPanel;
public class myPanel extends JPanel{
private JButton randButton=new JButton("Draw");
private double[] temparray = new double[]{70.05d, 10.20d, 25.00d, 50.53d, 40.60, 100.00};
private float[] timearray=new float[] {8.15f, 8.45f, 9.15f, 9.45f, 10.15f, 10.45f};
private double oldy;
private float oldx;
Graphics2D g2;
public myPanel() {
randButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
}
});
add(randButton);
}
public void paint(Graphics g) {
g2 = (Graphics2D) g;
g2.drawLine(30,400,30,100); // y koordinaciu asis
g2.drawLine(30,400,500,400); // x koordinaciu asis
g2.setColor(Color.BLUE);
oldy=0.0d;
oldx=0.0f;
for(int i=0;i<timearray.length*40;i+=40) {
g2.draw(new Line2D.Double(70+i-40, 400-oldy, 70+i, 400-temparray[i/40]));
oldy=temparray[i/40];
oldx=timearray[i/40];
g.setColor(Color.RED.brighter());
g.drawOval(70+i-2, (int)(400-temparray[i/40]-2),4,4);
for(int j=0; j<300; j+=20){
g.drawString(""+j+"", 4, (int)(400-j));
}
// g.drawString(""+(int)oldy+"", 4, (int)(400-temparray[i/40]-2));
g.drawString(""+oldx+"", 70+i-2, 420);
g.setColor(Color.BLUE);
}
g.setColor(Color.RED);
g.drawString("Temperature", 10, 80);
g.drawString("Time", 550, 400);
}
}
Fri May 18, 2007 3:08 pm
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;
/**
*
* @author mohamed
*/
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 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());
// Do Your Zooming Process
}
}
Download the Project from here
Fri May 18, 2007 3:13 pm
Mon Jun 25, 2007 2:00 pm
Mon Jun 25, 2007 4:03 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.