Make Own Color To Use With Awt

Aug 22, 2014

I am stuck. I was trying to make my own Color to use with awt.

I used the statement :

public static final Color purple = new Color(255,0,255);

When I try to use Color.purple it says it cannot reference purple.

View Replies


ADVERTISEMENT

Color Memory - How To Make Cursor Appear In Each Guess Box

Dec 7, 2014

This is my code. It is running great until I enter in the final color and hit enter. I get an Array Index out of bounds error, which I show at the bottom. I have fiddled with it, by moving the all answers correct into an if..else statement, hoping it would fix it. Needless to say, it didn't work.

Also, I am trying to figure out how to make the cursor appear in each guess box. It does in the first one, but after I hit enter, I have to click in the box each time to get one.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class RobertMaloneChapter17 extends JFrame
{
//final variables to set the width and height of my frame

[Code] ....

My Errors:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 5
at RobertMaloneChapter17$Listener.actionPerformed(RobertMaloneChapter17.java:67)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:508)
at javax.swing.JTextField.postActionEvent(JTextField.java:721)

[Code] ....

View Replies View Related

JavaFX 2.0 :: Setting Background Color For Layout - Fill / Color On OS X

Jun 10, 2014

No problem setting background color for layouts, e.g. bdrPn.setBackground(new Background((new BackgroundFill(Color.BLACK, CornerRadii.EMPTY, Insets.EMPTY))));
 
But neither of the following are working for me, running JavaFX 8 on latest OS-X
 
scene = new Scene(bdrPn, winW, winH, Color.BLACK);
scene.setFill(Color.BLACK); 
scene.setFill() worked fine for previous versions of JavaFX.

View Replies View Related

Can't Get Background Color To Change From Basic Gray Color

Oct 20, 2014

I've just started working on a program and i'm already having difficulties with the program. I can't get the background color to change from the basic gray color. Maybe you can tell me what i'm doing wrong.

import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.awt.*;
import java.lang.Object;
import java.awt.Color;
public class FrameDemo{
public static void main(String args[]){
Toolkit toolkit = Toolkit.getDefaultToolkit ();

[Code]...

also if theres any way to shorten up what I have there, that would be great.

View Replies View Related

Input String Color Name And Set It To Color Object

Nov 24, 2009

If I want to read from file the word "red" And then the following is not the right way like in the code ,, How to set the Color name

File inputFile = new File ("C:\input.txt");
Scanner scan = new Scanner (inputFile);
String RedColor=scan.nextLine();
Color backColor = new Color(redColor);

View Replies View Related

Rubik Cube - Aligning Middle Side Color With Bottom Middle Side Color

Jan 16, 2015

I am trying to align the core/middle side color of a cube, index 4, with the bottom middle color of the same side, index 7. (Each side has values 0-8 where 0 - is the top left corner, 1 is the top mid corner, 2 is the top right corner, 3 is the middle left corner, etc).

In addition to lining up those two colors, I am also making sure that the neighbor color of index 7(the color that it is attached), in this case the bottom color, matches with the top core/middle color. I will attach some pictures and a print out to show what I am talking about...

However, in my code when I am trying to align all of these up together, it does not go into the while loop. Each of the loops essentially is trying to get a match of same color with index 4 and 7, as well as making sure that index 7's neighbor color (the bottom color, in this case) matches with the top color.

Here is what I have tried:

private void alignSideColor(){//make the bottom colors neighbor match with a middle side value and rotate it to the top, for the top cross

if(cube.bottom.square[1].charAt(0) == topColor){
while(cube.front.square[7].charAt(0) != frontColor && cube.bottom.square[1].charAt(0) != topColor){
rotateBottomClockwise(1);
System.out.println("Trying to align side color...");

[Code] .....

The print out of the ELSE IF is:
alignment is: W-G and tops: R-R
NOW ITS ALIGNED
even though the sides, index 4 and 7, are NOT aligned with each other

I have also tried the same thing but with out the 2nd condition in each while loop, and although is DOES enter the while loop, it does not perform correctly -- index 4 and 7 WILL have matches colors, but it does not check to see if index 7's neighbor matches with the top color.

Here is how it prints out
** ** ** G7 B6 Y1 ** ** **//this portion is the back of the cube
** ** ** R6 W5 O4 ** ** **
** ** ** R3 W2 O1 ** ** **
B3 G4 Y9 W9 O8 Y7 W3 B4 G9//this portion is the left, top, and right of the cube
B2 G5 R8 W4 R5 Y6 O2 B5 G8
O7 W8 R9 B7 B8 B9 R1 R4 R7
** ** ** O3 O6 O9 ** ** **//this portion is the front of the cube
** ** ** Y2 Y5 Y8 ** ** **
** ** ** B1 G6 W7 ** ** **
** ** ** Y3 Y4 G1 ** ** **//this portion is the bottom the cube
** ** ** R2 O5 G2 ** ** **
** ** ** W1 W6 G3 ** ** **

Here is the cube showing the top, left and front side

Here is the left and bottom side. As you can see index 4, G5 -- yes that is a 5 lol -- does not have the same color as index 7, W8.

I need to rotate the bottom until W8 is aligned with a middle white value. An examples of a neighbor is: W8-R2

View Replies View Related

Make Shapes Besides Making Two Lines For X And Oval With White Smaller Oval Inside To Make O

May 8, 2014

We are making a tic tac toe game for my CS120 class and I am having trouble figuring out how to make our X's and O's. Is there a way to make shapes besides making two lines for an X and an oval with a white smaller oval inside to make an O? We have only learned the basics so far in class (i.e. events, inheritance, client-supplier, etc.)

These are our instructions:

Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will 1) create a TicTacToeModel 2) create a TicTacToeView and 3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided (a view of the game, a button, and a text field to enter the cell). A sample screenshot is displayed below.And this is the code i have thus far:

[import java.awt.*;
import javax.swing.JFrame;
public class TicTacToeView extends Rectangle
public TicTacToeView(int x, int y, int w, int h) {
super(50,60,w,h);
this.setBackground(Color.red);
JFrame win = new JFrame("Tic Tac Toe");
win.setBounds(10,10,w+100, h+100);
win.setLayout(null);
win.setVisible(true);
win.setBackground(Color.gray);

[code]....

View Replies View Related

How To Set A New Color In Gridworld

Mar 14, 2014

I've been using grid world with my school. It's a part of the eimacs textbook. the following code that I wrote for gridworld. It's a very small tad bit of code:
 
Actor actor = new Actor();
actor.putSelfInGrid( grid, new Location( 5, 3 ) );
public void setColor (Color RED);

I get the following error:

error: illegal start of expression
 
public void setColor (Color RED);

View Replies View Related

Color And Date

May 27, 2014

I am working on a chat programme and I was wondering how to separate the both usernames for example:

Server is me , and Client is the first man who had connected to me , so I want to be

Server to be in green color , and Client to be in Red

Server(green):Hi

Client(red):hello

Server(green):How you doin'

Client(red):Fine

My second question is both of em' to have minutes and dates for example

27.05.2014 11:30pm Server(green):Hi
27.05.2014 11:31pmClient(red):hello
27.05.2014 11:32pmServer(green):How you doin'
27.05.2014 11:33pmClient(red):Fine

View Replies View Related

How To Change Color Of Cursor

Jan 17, 2014

I'm programming in school using Netbeans and we've just started with graphical programming (i.e JPanel, JClass, JFrame). This is my first assignment and the purpose of this program is that when you press the mouse you will fill 4 circles with diffrent colors. I've managed to draw 4 circles with diffrent colors but I want my cursor to change color simultaneously. Here's my code so far ....

//Java klass "Klick"
public class Klick {
//Medlemsvariabler.
private int x = 0;
private int y = 0;
private int r = 1;
public int antal = Rityta.antalKlick;

[Code]...

View Replies View Related

Swing/AWT/SWT :: Color Is Not Changing

Jan 29, 2015

Color only changes, when resizng frame with mouse, not when clicking.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SimpleGui1 implements ActionListener {
JFrame frame;
MyDrawnPanel drawnPanel;

[Code] .....

View Replies View Related

Obtain Color From Borders

Oct 10, 2014

I'm doing this project where I need to make a persian carpet using recursive methods. I already have my recursive what I'm trying to implement is the use of color. My method BorderColor draws a square using a random color choose from an array.

public void Cuadrado(Graphics g){
Random color = new Random();
g.setColor(colors[color.nextInt(colors.length)]);
g.drawLine(left, top, right, top);
g.drawLine(left, top, left, bottom);

[Code] ....

What I'm trying to do is getting the color from 4 different corners in order to create a new one and make a recursive call. I already tried using the method getPixelColor from the Robot() object but I quit it because is a recursive method and it may cause trouble with the recursive stack. I created this method to create the new color and then call it in the PersianRug method, but I dont have a clue on how to obtain and implement the new colors.

public int newColor(int c,int c1,int c2,int c3, int a){
int c4=((c+c1+c2+c3)%13)*a;
return c4;
}

View Replies View Related

How To Set Color When Space Is Pressed

Apr 11, 2014

The title says it all and i'm a fairly new java programmer but here is the code:

package TestVersion;
import java.awt.Color;
import java.awt.Graphics;

[Code]......

I think i need a variable or something oh and here is the 2 other classes, the keylistener one:

package TestVersion;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

[Code].....

View Replies View Related

Color One Column In JTable

Jan 6, 2015

how I can highlight one column with color? When i add color to a column the entire table is colored.

View Replies View Related

Creating UML And Changing Color?

Oct 20, 2014

The Toys of the Future Company has decided to issue a new line of toy robots. While they are not sure exactly what their robots will look like, they do know the functionality that they will all have. All robots will be able to move forward, turn right, turn left, spin and detect an object in front of it via a sensor. The robot will use a touch sensor to determine whether it has hit an object in front of it, such as a wall. The robot will have two, three, or four wheels, but it will only be driven by two of them: a right wheel and a left wheel. Each wheel will be attached to a motor that controls it.

* ^ this is only something to think about
Produce a UML class diagram.

Using UML, describe the objects and classes that will be associated with this new toy. Either hand draw or use an appropriate UML creation tool to generate a UML design document for your Robot class. Create a set of classes that can be used to control the robot.

Develop your new class.

Create a new NetBeans project entitled, "Assignment_8_1" and develop your new class. Now, using the objects and classes that you have written, write a program for your robot that allows it to move in a large square. Allow your robot to run in a big two dimensional array and every time the robot encounters a square in your array, turn that square black.

So here is the code for the moving ball:

package ballapplet;
import java.awt.*;
import java.util.Formatter;
import javax.swing.*;
public class BallApplet extends JPanel {
private static final int BOX_WIDTH = 640;

[Code] ....

I want to know how to change the color of an object, and how to move it in specific directions.

View Replies View Related

Set Background Color With Check Box?

Apr 9, 2014

the program runs fine with exception of color background change.. dont laugh at code.

package chapter7;
import java.awt.*;
import java.awt.event.*;

[Code].....

View Replies View Related

Applet Color And Font

Feb 25, 2014

I am new to applets and I am trying to create a program to display color and font. See my code below, I am getting some errors below.

import java.awt.Graphics; //program uses class Graphics
import javax.swing.JApplet; //program uses class JApplet
import javax.swing.JOptionPane; //program uses class JOptionPane
public class AdditionApplet extends JApplet
{
private double sum; //sum of values entered by user
private double average; //average of values entered by user

[Code] .....

java:11: error: cannot find symbol
Color skyBlue;
^
symbol: class Color
location: class AdditionApplet
java:12: error: cannot find symbol
Font sansFont;

[Code] .....

6 errors
Process completed.

View Replies View Related

Way To Give A Color To The JFrame

Nov 23, 2014

i've worked with java for 1 month, i'm designing some practices at Netbeans IDE. my problem is i tried to make a single colorful interface using panels, adding colors and i want to know if i exist a way to give a color to the JFrame (i tried to use the background color option but this didn't work).

View Replies View Related

How To Use Member Of Color Class

Nov 5, 2014

i have two classes in two different files.i have this class:

Java Code:

public class Color
{
private int red;
private int green;
private int blue;

public Color(){
red = 0;
green = 0;
blue = 0;
} mh_sh_highlight_all('java');

And i have this class :

Java Code:

public class Light
{
private Color color1;
private boolean switchedon;

public Light(int red, int green, int blue){
//dont know what to write here . how can i use the members of the Color class here ? without using extends.
}
} mh_sh_highlight_all('java');

View Replies View Related

Web Application - String Color On UI

Sep 4, 2014

I have a web application on which "Hello There" is getting printed via a bean StringBuilder as follows.
 
StringBuilder sb = new StringBuilder();
 
sb.append("Hello There");
 
and in jspx I do see Hello There in black color.
 
I want Hello There to be in blue color. How do I do that ?

View Replies View Related

How To Change Background Color Of Panel

Oct 23, 2014

I have a Jpanel with JButtons on the panel is it possible to change the background color of the pannel but leave the JButtons thr default color

View Replies View Related

Combobox To Change Color And Shape

Nov 19, 2014

i java a project with java draw golf course and currently working on 2 combo boxes to change shape of the flag on the post and fill color as well on combo box item change. I have below code. as am new to java what to do next.

import java.awt.*;
import java.awt.event.ItemEvent;
import javax.swing.*;
public class GulfCourse extends JPanel{
public void paintComponent( Graphics g){
super.paintComponents(g);
//draw green oval

[Code]...

View Replies View Related

How To Change Background Color Of Console

Mar 30, 2014

I'm using eclipse to run my java program.

I want to be able to change the background color of the console when the user types in a particular command..

e.g User types: color blue

Then the background color of the console should turn blue

Is this possible and how would I go about doing it?

View Replies View Related

Random Color Font And Position?

Jun 18, 2014

How do i set a random font in java and random position on screen. I've got random color but cannot get the font and position to change except for two times.

import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class JChangeSizeAndColor extends JPanel implements ActionListener {
private Random generator;

[code]....

View Replies View Related

Losing Color During Image Conversion Using JAI

Jan 20, 2015

I've been using Java Advanced Imaging to convert tiff images to jpeg. The code I'm using is pretty simple, and I'll include it below:

Java Code: private static void convertImage(File tiff_src, File jpg_dest)
{
if (tiff_src == null || !tiff_src.exists()) throw new IllegalArgumentException();
try
{
SeekableStream stream = null;

[code]...

The problem when I run this code is that during conversion, the decoder or encoder seems to drop a good deal of black. I'd like to include examples, but the tiff images are about 30 MB...I've tried configuring the decode parameters, as well as the encode parameters, but like I said, somewhere during conversion I drop a good deal of the black from the image.

View Replies View Related

Translating Grayscale Image To Color

Aug 3, 2014

I have a greyscale image with alpha. I also have a colour. I want to change that greyscale image to the colour specified, with black remaining black and white being the specified colour, and the different shades of grey between becoming the shade of the specified colour.I've got a couple of different thoughts about how to solve it myself, but I rather hope there's an easier way.

Solution one would be to use a BufferedImage and just use getRGB/setRGB excessively.The second solution would be to use the above and cache the result. Given that there can be up to 10 different colour schemes, and up to approx. 2000 different images, this can, in the end, become excessively memory-hogging (although the general case would likely be 3 colours and perhaps a hundred or two images). It would also mean I'd have to loop through all images whenever the user changes the colour.

Is there a magical third solution that can translate a greyscale image to colour on-the-fly that's fast enough to run hundreds of thousands of times per second? No code available since this is just in the thought process right now.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved