Hi,
I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing in the right direction.
Ok the problem.
I am creating a program that ask the user to input a height value, the program will then do a calculation and create a golden ratio width. The type of both the height and the width are double.
This is where the problem starts. The next thing I need to do is make the program draw the rectangle using the user inputted height and the calculated width.
I have a feeling that the problem has occured because I haven't converted the type double into a int type.
Here is my code -
-
import java.awt.*;
-
import javax.swing.*;
-
import java.applet.Applet;
-
import java.awt.Graphics;
-
-
/**
-
* Class Test - write a description of the class here
-
*
-
* @author (your name)
-
* @version (a version number)
-
*/
-
public class Test extends JApplet
-
{
-
// instance variables - replace the example below with your own
-
double sum;
-
int height;
-
int width;
-
-
/**
-
* Called by the browser or applet viewer to inform this JApplet that it
-
* has been loaded into the system. It is always called before the first
-
* time that the start method is called.
-
*/
-
public void init()
-
{
-
String firstNumber;
-
double number1, sum1;
-
-
firstNumber = JOptionPane.showInputDialog("Please enter the height" );
-
-
-
number1 = Double.parseDouble( firstNumber );
-
-
-
sum1 = (Math.sqrt(5) + 1) / 2;
-
sum = number1 * sum1;
-
-
int height = (int)number1;
-
int width = (int)sum;
-
-
-
-
-
// this is a workaround for a security conflict with some browsers
-
// including some versions of Netscape & Internet Explorer which do
-
// not allow access to the AWT system event queue which JApplets do
-
// on startup to check access. May not be necessary with your browser.
-
JRootPane rootPane = this.getRootPane();
-
rootPane.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
-
-
// provide any initialisation necessary for your JApplet
-
}
-
-
/**
-
* Called by the browser or applet viewer to inform this JApplet that it
-
* should start its execution. It is called after the init method and
-
* each time the JApplet is revisited in a Web page.
-
*/
-
public void start()
-
{
-
// provide any code requred to run each time
-
// web page is visited
-
}
-
-
/**
-
* Called by the browser or applet viewer to inform this JApplet that
-
* it should stop its execution. It is called when the Web page that
-
* contains this JApplet has been replaced by another page, and also
-
* just before the JApplet is to be destroyed.
-
*/
-
public void stop()
-
{
-
// provide any code that needs to be run when page
-
// is replaced by another page or before JApplet is destroyed
-
}
-
-
/**
-
* Paint method for applet.
-
*
-
* @param g the Graphics object for this applet
-
*/
-
public void paint(Graphics g)
-
{
-
// simple text displayed on applet
-
g.drawRect( 15, 10, 270, 20 );
-
g.drawString("The sum is " + sum, 25, 25 );
-
g.drawRect( 100, 100, height, width);
-
-
-
}
-
-
/**
-
* Called by the browser or applet viewer to inform this JApplet that it
-
* is being reclaimed and that it should destroy any resources that it
-
* has allocated. The stop method will always be called before destroy.
-
*/
-
public void destroy()
-
{
-
// provide code to be run when JApplet is about to be destroyed.
-
}
-
-
-
/**
-
* Returns information about this applet.
-
* An applet should override this method to return a String containing
-
* information about the author, version, and copyright of the JApplet.
-
*
-
* @return a String representation of information about this JApplet
-
*/
-
public String getAppletInfo()
-
{
-
// provide information about the applet
-
return "Title: \nAuthor: \nA simple applet example description. ";
-
}
-
-
-
/**
-
* Returns parameter information about this JApplet.
-
* Returns information about the parameters than are understood by this JApplet.
-
* An applet should override this method to return an array of Strings
-
* describing these parameters.
-
* Each element of the array should be a set of three Strings containing
-
* the name, the type, and a description.
-
*
-
* @return a String[] representation of parameter information about this JApplet
-
*/
-
public String[][] getParameterInfo()
-
{
-
// provide parameter information about the applet
-
String paramInfo[][] = {
-
{"firstParameter", "1-10", "description of first parameter"},
-
{"status", "boolean", "description of second parameter"},
-
{"images", "url", "description of third parameter"}
-
};
-
return paramInfo;
-
}
-
}
-
-
-
Thanks for any suggestions.
1 2370 Nepomuk 3,112
Recognized Expert Specialist
...This is where the problem starts. The next thing I need to do is make the program draw the rectangle using the user inputted height and the calculated width.
I have a feeling that the problem has occured because I haven't converted the type double into a int type...
First of all, welcome to TSDN!
About your problem: What DOES happen? And if you think, the problem has happened, because of the missing conversion, have you tried converting it?
Greetings,
Nepomuk
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Remon Huijts |
last post by:
Hi there,
For a very specific service, I have created a PHP script that uses the GD
library functions to create a PNG image from a few lines of XML data
describing a simple diagram/drawing. It's cool and works, writing the XML
data in a text editor is straightforward for me because I designed the
format. I have no idea however how I can...
|
by: timtt |
last post by:
does anyone guideline to speed up drawing in awt applet??
i have thousands of g.drawstring() + d.drawline()
actually, does Swing applet draw much faster than awt applet??
|
by: Hermund ?rdalen |
last post by:
Hi!
We're developing some children's pages for one of our customers.
Already we've found some nice crossword and puzzle programs/applets.
What we really need now is a drawing program.
It must be possible to specify a start image and it must be possible
to store the drawing once you're through. We tried aDraw but we
couldn't get past a...
|
by: Tomi Holger Engdahl |
last post by:
I am looking for a solution to add on-line drawing tool
to a phpBB discussion board.
The idea would be that the users can draw their own
simple drawings with the tool and attach them easily
as images in the discussion. The idea is to easily
add small drawings to the postings.
The drawign tool should be easy to use and learn.
It should...
|
by: Champika Nirosh |
last post by:
Hi,
I want to create drawing board application that can draw Line, rectagle,
circle and free hand drawing.
Each drawing need to be transparent, moveable (draggable), have bring to
front and send to back feature etc.
How can I do this .. where should I start?
| |
by: barbaros |
last post by:
Hello everybody,
I need to put some dynamic drawings on my web page. More precisely, I
need to draw a number of geometric figures (circles, rectangles) which
evolve into a graphics windows according to some law (a little bit like
the solar system). I need also to have several fields aside the window,
where the visitor can change values for...
|
by: lonertic |
last post by:
Hi, I'm new to the forum,
I'm hoping someone can help me with this because days of googling and lots of coffee hasn't so far..maybe I'm not using the right keywords to search.. I don't know..
I'm writing a .EXE integration program with VB, the program contains an IE Browser ActiveX control which navigates to a html page onload (which...
|
by: cozsmin |
last post by:
Hy all,
i have aproblem, i made a simple applet that works fine at a first glance,
so i just wanted to add some drawing on it like :
class Ap extends java.applet.Applet {
java.awt.Graphics g;
public void start() {
|
by: Madmartigan |
last post by:
Hi
I'm a newbie to C# and have been instructed to create a Hangman game in SharpDevelop. I don't want the answer to the full code, just some help along the way.
I have included my code thus far and at this stage would like to know how I can get the RandomWordManager, which I found on another site, to display a newly generated word as the...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |