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
ADVERTISEMENT
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
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
Feb 20, 2014
I created this simple vector java program where ball falling and when collide with the bar below, the ball stops.
I need to make the ball falling randomly from different direction and also need to make the bar move left right using keyboard arrow.
Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
//using timer to increase the counter
[code].....
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
Dec 8, 2014
The program I'm supposed to create generates a random number between one to ten. Then the program is to ask me if I wish to cross the road. If you choose to cross, the outcomes for 0-2 are "You crossed safely." For 3-5, 75% of the time it should say "RIP you got run over", and 35% of the time it should say "You crossed the street." For 6-8, 60% of the time it should say you made it.", and 40% of the time it should say "You died". For 9-10, it should say "RIP".
So far I have gotten the random number generation part working. I have up to here:
import java.util.Random;
public class test4 {
public static void main(String[] args) {
Random random = new Random();
for(int i =0; i < 1; i++){
int num = random.nextInt(10) + 1;
System.out.println("The number of cars on the street are: " + num + "Do you wish to cross the road?");
}
}
}
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
Jun 19, 2014
How can I set a new Mouse position ?
Is there any class that represent the Mouse ...
The cursor class is without this ability ...
View Replies
View Related
Jul 8, 2014
I have to insert certain lines of html code in already existing file of html using java.I have to add certain things in head and some things in body.
View Replies
View Related
Aug 3, 2014
So I need to print out the table of conversions from kilogram to pound and from pounds to kilograms. I think I have done a while loop correctly, but it is hard to actually check it since I do not have proper output format. I have tried also %4.2f format option however could not find the proper position in the print.
public static void main (String[] args){
System.out.printf("%10s%10s | %10s%10s
", "Kilograms", "Pounds",
"Kilograms", "Pounds");
System.out.println("---------------------------------------------");
[code]....
View Replies
View Related
Nov 4, 2014
I am developing an application where blind person can interact with computer i have completed the part where computer responds as per command given by user.The part where i am stuck is i want to give voice feedback as user moves the curser for example if mouse is on d drive then user should get feedback that its d drive....i want to do it for whole windows ...
View Replies
View Related
Jun 4, 2014
I can't recolate and align the button, the circle or the line where i want it to on the canvas. I want to be able to move the line where i want it, now it seems like all objects are stuck in the middle of the scene or canvas.
package application;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
[Code] ....
View Replies
View Related
Nov 6, 2014
I need to make a simple applet, but I'm stuck with something. This is how my applet should look:
And this is how that part looks in my applet:
What I've done until now is create one JPanel which includes two other JPanels.. The first one contains only the JTextArea you can see, and the other one includes the other elements.
I just need to make the JTextArea taller, like in the example, so everything comes into place...
View Replies
View Related