The Artima Developer Community
Sponsored Link

Java Answers Forum
Integer Input Methods

1 reply on 1 page. Most recent reply: Dec 21, 2002 9:18 AM by Jay Kandy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
GW

Posts: 1
Nickname: graemew
Registered: Dec, 2002

Integer Input Methods Posted: Dec 21, 2002 8:13 AM
Reply to this message Reply
Advertisement
Hi all,

Im a complete Java newbie I have programmed in C++ and other languages before, I have JBuilder 6 to compile my work. Im building a small applet for a project, the applet will accept RGB values and display the colour on screen, very very simple I had imagined. I know i can do it via the colourchooser but I don't want to use that.

Originally I had planned to three textfields one for red, one for green etc. The user would enter an integer (max 255) the value would be assigned to defined integer variable and that would be fine. I soon realised java stored data entered through a textfield as a string. I used the convert function to convert the string into an integer.

I wanted these three integers used in creating a new colour:
cmdCustomColour.setBackground(new Color(int iRed, int iGreen, int iBlue));

But this isn't possible either, I get a load of error messages.

I have quite a few questions to ask, but would someone mind advising me on this one first?

What is the best way to accept the input of the integers? Is it possible to use my method above? Would I be best using a scroll bar?

Thanks all,

I look forward to recieving your advice.


Jay Kandy

Posts: 77
Nickname: jay
Registered: Mar, 2002

Re: Integer Input Methods Posted: Dec 21, 2002 9:18 AM
Reply to this message Reply
Heres how you get input and setBackground(). Be sure to do some error-checking and other pretty stuff. Why scrollbar?

import java.awt.*;
import java.util.*;
import java.applet.*;
import java.awt.event.*;
 
public class ColorApplet extends Applet
{
	Button button 	= null;
 
	Label redLabel 		= null;
	Label greenLabel 	= null;
	Label blueLabel 	= null;
 
	TextField red 	= null;
	TextField green = null;
	TextField blue 	= null;
 
	public void init()
	{
		button 	= new Button("Update");
 
		redLabel 	= new Label("Red");
		greenLabel 	= new Label("Green");
		blueLabel 	= new Label("Blue");
 
		red 	= new TextField("");
		green 	= new TextField("");
		blue 	= new TextField("");
 
		add(redLabel);
		add(red);
		add(greenLabel);
		add(green);
		add(blueLabel);
		add(blue);
		add(button);
 
		button.addActionListener(
			new ActionListener(){
				public void actionPerformed(ActionEvent e)
				{
					int redValue = Integer.parseInt(red.getText());
					int greenValue = Integer.parseInt(green.getText());
					int blueValue = Integer.parseInt(blue.getText());
 
					setBackground(new Color(redValue, blueValue, greenValue));
					repaint();
				}
			});
	}
 
	public void paint(Graphics g)
	{
	}
}


-Jay

Flat View: This topic has 1 reply on 1 page
Topic: How can i order in decending order Using hash set Previous Topic   Next Topic Topic: removing exit permission from security.policy

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use