Total members 11893 |It is currently Tue Nov 05, 2024 12:45 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka



Go to page 1, 2  Next


This is a netBeans project using Java.This is Program Draw a 2D curve.It include Y aixs for the Temperature and X aixs for Time.Temperature is any array created Randomly.The size of this array is 100 int[].The Time is 0-100.The User Can Determine the Max Temperature with Range 200-0. I am using the Random Class to fill the Temperature array.

The GUI contain textfiled to determine the Max Temperature and JButton to fill the Temperature array with a new Random integers numbers .
Attachment:
File comment: NetBeans Project Curve X-Y.
XYCurve.rar [11.88 KiB]
Downloaded 1149 times


The Project Contain two classes.
    myFrame.java
    myPanel.java


The myFrame.java
java code
/*
* 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();
}

The myPanel.java
java code
/*
* 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);
}

}




_________________
Recommend my post if you found it helpful.


Author:
Newbie
User avatar Posts: 15
Have thanks: 0 time

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?


Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time

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 ?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

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 ?


an example i have double[] temparray = {7, 10, 25, 50, 30} and double[] timearray = {8.15, 8.45, 9.15, 9.45, 10.15}

using these values i have to draw a curve. later i will have to add other values in these two arrays but not from GUI side(if you understand that), like this add(newTemp, new java.util.Date()); i don't know that these are correct.


Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time

Here it is , I made it on your example , and i also add Point Circles on the Curve to determine the Postions of the Given Temp points , Very Happy

I hope that i make somthing useful ,
Attachment:
File comment: Curve
Curve.GIF
Curve.GIF [ 7.4 KiB | Viewed 6535 times ]

Attachment:
File comment: The Project
XYCurve.rar [11.21 KiB]
Downloaded 1201 times


I made changes only in this class , (myPanel.java)
Code:


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);
    }
   
}


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

by the way which file i have to run?

Quote:

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)




Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time

then i want to compile myFrame.java look at this

Z:\xycurve\src\xycurve>javac myFrame.java
myFrame.java:38: cannot find symbol
symbol : class myPanel
location: class xycurve.myFrame
myPanel cpanel=new myPanel();
^
myFrame.java:38: cannot find symbol
symbol : class myPanel
location: class xycurve.myFrame
myPanel cpanel=new myPanel();
^
2 errors



Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time

if I change
Code:
private int[] temparray=new int[]{7,10,25,50,30};
to
Code:
private double[] temparray=new double[]{7,10,25,50,30};
it will be correct?


Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time

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};


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

msi_333 wrote:
Makaule wrote:
if I change
Code:
private int[] temparray=new int[]{7,10,25,50,30};
to
Code:
private double[] temparray=new double[]{7,10,25,50,30};
it will be correct?


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};



thanks for this


Author:
Newbie
User avatar Posts: 37
Have thanks: 0 time
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

  Related Posts  to : Curve XY 2D
 text like a curve     -  
 Draw Hermite Curve     -  
 Curve Control Point in java     -  
 Draw Bezier Curve and selecting the points with mouse click     -  
 Draw curves using Hermite Curve equations with mouse clicks     -  
 draw 2d curve with showing x axis and y axis     -  



Topic Tags

Java Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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