Total members 11894 |It is currently Thu Nov 21, 2024 11:44 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






* Project Name:   CurveXY
* Programmer:   msi_333
* Type:   Graphics]
* Technology:  Java
* IDE:   NetBeans
* Description:   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: Screenshot
Graph.GIF
Graph.GIF [ 9.27 KiB | Viewed 7740 times ]

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

}





Attachments:
File comment: Project source
XYCurve.rar [11.85 KiB]
Downloaded 1067 times

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

This artcile went ahead and made my day.



Author:

updated.


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


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 3 posts ] 

  Related Posts  to : draw 2d curve with showing x axis and y axis
 Repeat background image on y axis     -  
 Repeat background image on x axis     -  
 Draw Hermite Curve     -  
 Draw curves using Hermite Curve equations with mouse clicks     -  
 Draw Bezier Curve and selecting the points with mouse click     -  
 bmiles v1.0 - images are not showing     -  
 avoid showing/printing figures, text after conclusion     -  
 Curve XY 2D     -  
 text like a curve     -  
 Curve Control Point in java     -  



Topic Tags

Java Projects, 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