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
ADVERTISEMENT
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
Apr 19, 2015
I'm new in Java. I try to create a menu with items like "Font size", "Font color" type of "font" how to create a menu with that options.
Java.jpg
View Replies
View Related
Mar 9, 2014
I am having problem with the JRadio Buttons to change the font color in my code. What needs to be done? Also if I were to connect this GUI to another GUI and save font colors, how would I go about that?
package SystemandDesign.RISK;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.JFrame;
import javax.swing.ButtonGroup;
[code]....
View Replies
View Related
Nov 23, 2014
I am trying to go about making this applet a bit different then normal. The issue I am having is it is drawing an applet but, not the right dimensions, it's able to be resized, lastly the background color is not being set. I mean, I suppose I could call paint() and just draw it out but, I read that I could make the applet pop out to the dimensions I would like. None of this is working sadly.
package com.powder.game;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.io.IOException;
import java.lang.Math;
[code]...
my exact question is can I rewrite the applet to make a pop out window and should I just call paint()?
View Replies
View Related
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
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
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
Apr 21, 2014
I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.
I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.
I found an example from which I coded:
Font font = UIManager.getFont("OptionPane.font");
UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24));
font = UIManager.getFont("OptionPane.font");
JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon
After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.
And yes I understand that, when this works, it will affect every JOptionPane in my program.
I also tried:
Font font = UIManager.getFont("OptionPane.font");
JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE);
JDialog dlg = message.createDialog("About Mover");
[Code] ....
This gave me a dialog with the default font and an unwanted icon.
So I tried
// both
Font font = UIManager.getFont("Dialog.font");
// and
Font font = UIManager.getFont("JDialog.font");
and planned to use that font in my setFont() call but font was null.
View Replies
View Related
Feb 14, 2015
I was wondering, if, for example I set font for my textarea like this:
area.setFont(new Font("Serif", Font.ITALIC, 18));
Is that last parameter, in this case 18, will be actually the same size for all users? Maybe I should avoid these absolute numbers?
View Replies
View Related
Feb 19, 2015
It's very simple, I've added an AWT component/control (specifically a Choice object to a Frame. It's a pop-up menu by any other name.
Above the pop-up, there's a label. I'm trying to change its font to no success.
* I create Label object called label1: Label label1 = new Label("This is a pop-up")
* I create a Font object called f: Font f = new Font("Times New Roman, Font.BOLD, 18)
* I apply the new font to the label: (in AFrame's constructor) label1,setFont(f)
When displayed the label's font seems to be stuck on Arialor something similar. Changing the point size however does have an effect.
import java.awt.Choice;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
/**
* Defines a 'pop-up' AWT control that will be added to AFrame.
* It extends Choice - I may need extra functionality later.
*/
public class APopUp extends Choice implements ItemListener {
// instance variables
int noi; // no of items
String selected; // item selected from choice
[Code] ....
View Replies
View Related
Feb 14, 2014
I am having some troubles with a program fileviewer where you must be able to change font style and size when pressing JButton "Set font". I have solved the most of the program and every menu button is working but I don't know how to set in FileListener class method to change the font when running in main class. Anyway, this is my FileListener class
Java Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.Font;
public class FileListener implements ActionListener
[code]....
View Replies
View Related
Jan 20, 2014
The Font style constants are of int: int[] fontStyleList = new int[] {Font.PLAIN, Font.BOLD, Font.ITALIC};But what do I do when I want to add the names such as PLAIN etc. as the name of a menu item?
The following is not going to work, right!String[] parts = (fontStyleList[i].toString()).split("."); or String[] parts = ("" + fontStyleList[i]).split(".");rbStyle = new JRadioButtonMenuItem(parts[1]);
Is there another way to do this or should I just do another array with the names as a String?
View Replies
View Related
Jun 1, 2014
I'm trying to display a phrase in every font size from 6 thru 20. As it stands now, the code below cascades the phrase, sort of, down the frame, but the font size doesn't change.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JFontSizes extends JFrame implements ActionListener
{
JButton button = new JButton("Press Me");
String aPhrase = new String("This is a phrase.");
[Code] ......
View Replies
View Related
Jun 1, 2014
This is what I have thus far.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
[Code]....
The result looks something like this:
Button
This is a phrase.
This is a phrase.
This is a phrase.
This is a phrase.
etc.
View Replies
View Related
Jul 5, 2014
I wish to print the content of a JTextArea. I know I can do this with textarea.print(). However, I wish to print in a different font, font size and orientation from that of the JTextArea itself. I have been able to change the orientation by setting print attributes
PrintRequestAttributeSet printAttributes =
new javax.print.attribute.HashPrintRequestAttributeSet ();
printAttributes.add(javax.print.attribute.standard .OrientationRequested.LANDSCAPE);
And then using the textarea.print() method that allows me to set attributes. However, I haven't found any way to set the font and font size.
View Replies
View Related
Feb 10, 2014
So, I have a game. I would like to make a game where you press "start" and THEN it starts. Also, I want to have collision with triangles, not just squares. The way I handle collision right now is with if statements, if the object is within the other, game over.How would I do collision with triangles? Lastly, how do I set a high score? how to change fonts and font size in swing?
View Replies
View Related
Mar 9, 2015
I'm working on Java-GUI implementation in Ubuntu. Used font-type in the application throughout is "Arial". At earlier stage of application it was the same font-type("Arial"). As the implementation grew the font-type has been changed automatically to another font type. It seems Serif-font type.
Now I could not able to figure out the problem; why it is so.
Note- I used HTML code also for setting font style of Dialog box messages and buttons. This is the only point which I figured out. Can it is ?
View Replies
View Related
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
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
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
View Related
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
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
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
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
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