Mon May 07, 2007 7:02 pm
/*
* myFrame.java
*/
package xycurve;
import javax.swing.JFrame;
/**
*
*/
public class myFrame extends JFrame{
/** Creates a new instance of myFrame */
public myFrame() {
getContentPane().add(cpanel);
setTitle("XY-Curve");
setSize(300,350);
setLocation(200,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new myFrame();
// TODO code application logic here
}
myPanel cpanel=new myPanel();
}
/*
* myPanel.java
*/
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.JTextField;
/**
*
*/
public class myPanel extends JPanel{
/** Creates a new instance of myPanel */
private JButton randButton=new JButton("Generate");
private JTextField myText=new JTextField(3);
private JLabel myLabel=new JLabel("Max Temperature ");
private Random myrand=new Random();
private int Max_temperature;
private int Min_temperature;
private int[] temparray=new int[200];
private int oldx;
private int oldy;
public myPanel() {
randButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Max_temperature=Integer.parseInt(myText.getText());
if(Max_temperature>200||Max_temperature200||Max_temperature<=0) {
Max_temperature=200;
myText.setText("200");
}
for(int i=0;i<100;i++) {
temparray[i]=myrand.nextInt(Max_temperature);
}
add(myLabel);
add(myText);
add(randButton);
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawLine(10,300,10,200);
g.drawLine(10,300,110,300);
g.setColor(Color.BLUE);
for(int i=0;i<100;i++) {
g.drawLine(20+i-1,300-oldy,20+i,300-temparray[i]);
oldy=temparray[i];
}
g.setColor(Color.RED);
g.drawString("Temperature(0 -"+Integer.toString(Max_temperature)+")",10,100);
g.drawString("Time (0-100)",120,300);
}
}
Thu May 10, 2007 1:27 pm
Thu May 10, 2007 1:36 pm
Makaule wrote:hello
thanks i think that this program help me for a while. But i need that time and temperature wouldn't be a random, and later i have to add new values of temp and time. temp max i have to find from array of temp, and temp min too.
so can you help me?
Thu May 10, 2007 1:49 pm
msi_333 wrote:Makaule wrote:hello
thanks i think that this program help me for a while. But i need that time and temperature wouldn't be a random, and later i have to add new values of temp and time. temp max i have to find from array of temp, and temp min too.
so can you help me?
So u want to enter the temp by ur self , I have a qestion ? What is the size of the temp array u want it to be [100] or ??
And then you search in it for the min and max ! right ?
Thu May 10, 2007 2:49 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.JTextField;
/**
*
* @author mohamed
*/
public class myPanel extends JPanel{
/** Creates a new instance of myPanel */
private JButton randButton=new JButton("Draw");
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();
}
});
add(randButton);
}
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);
}
}
Thu May 10, 2007 3:30 pm
Z:\xycurve\build\classes\xycurve>java myPanel
Exception in thread "main" java.lang.NoClassDefFoundError: myPanel (wrong name:
xycurve/myPanel)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Z:\xycurve\build\classes\xycurve>java myFrame
Exception in thread "main" java.lang.NoClassDefFoundError: myFrame (wrong name:
xycurve/myFrame)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Thu May 10, 2007 3:47 pm
Thu May 10, 2007 4:21 pm
private int[] temparray=new int[]{7,10,25,50,30};
private double[] temparray=new double[]{7,10,25,50,30};
Thu May 10, 2007 4:24 pm
private double[] temparray=new double[]{7.0d,10.0d,25.0d,50.0d,30.0d};
Thu May 10, 2007 4:26 pm
msi_333 wrote:Makaule wrote:if I changeto
- Code:
private int[] temparray=new int[]{7,10,25,50,30};
it will be correct?
- Code:
private double[] temparray=new double[]{7,10,25,50,30};
You have in java to to put the letter "d" for double and "f" for float so it will be :
- Code:
private double[] temparray=new double[]{7.0d,10.0d,25.0d,50.0d,30.0d};
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.