Implementing Methods - Draws Ovals Or Rectangles On Screen And Can Change Fill / Outline Color Of Shape

Oct 5, 2014

The following class is part of a homework assignment:

package event;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import model.Model;
import shapes.Rectangle;
import shapes.Shape;

[Code] .....

I have to implement the methods for what is happening if on some panel the action selected are Remove/Move/Change/Resize (Draw is already implemented).

The Applet in question draws ovals or rectangles on the screen and you can change the fill-color and outline-color of the shape. All this works already. I have dabbled with the move-method, but am not going anywhere.

View Replies


ADVERTISEMENT

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

Applets :: Drawing Ovals And Rectangles In JApplet With Two Separate Buttons

Apr 15, 2014

I'm not exactly sure what the draw button is supposed to do specifically, all i know is that it is supposed to draw both rectangles and ovals. The problem I am having is that when ever I click Draw Rectangle, it draws rectangles jusst the way I want but when ever I click Draw Oval, the program keeps drawing rectangles. I've tried repaint and clearRect methods but I did not manage to get them to work. I'm not sure what the problem is right here, I just cannot get it to work. Is there anything you guys can see that might be causing this? It's always good to have a different person look at it then myself. Also, I'm trying to implement a boolean for draw oval but I don't know where to put the if then.

public void init() {
length = new JTextField(10);
width = new JTextField(10);
btnDraw = new JButton("Draw");
btnClear = new JButton("Clear");
btnDrawRectangle = new JButton("Draw Rectangle");
btnDrawOval = new JButton("Draw Oval");

[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

Calculate Cost To Fill A Pool Based On Its Shape / Length / Width And Depth

Sep 17, 2014

This program is for a swimming pool filling service company. They charge 2 cents per gallon and $50 per hour to fill a pool. The truck can fill at a rate of 730 gallons per hour.

Create the Pool class that calculates the cost to fill a pool based on it's Shape, length, width and depth. (Input order is S L W D)

The pool class will need data fields for String shape, double length, double width, double depth, static double GallonsPerSqFoot = 7.4805, static double price per gallon = .02, static double FillingFeePerHour = 50.0, and static double FillingRate = 730gal/hr.

Create a No-Arg constructor and a constructor that accepts the non-static values, and has the methods: getShape, getLength, getWidth, getDepth, getGallons, getHours, getFillingFeePerHour, getHourlyCost and getTotalCost.

At the end of the class, create a main() method that asks for the input and returns the output based on the Pool class gets.. methods.

The shape options are oblong or rectangle. (A round pool would be oblong with the same width and height, a square pool would have the same width and height)

Formulas:
Rectangle cubic ft = length * width * depth.
Oblong cubic ft= ((Math.PI * Math.pow(width/2,2)* depth) +((length-width) * width * depth))
Gallons = cubic ft * 7.4805.
hours = total gallons/730.
Total cost = (total Gallons * .02)+(hours * $50)

Example Output
An oblong pool 18.00 feet long by 12.00 feet wide and 5.00 feet deep will use 6923.10 gallons of water and take 9.48 hours to fill. The total cost will be 612.65.

Here is my code:

import java.util.Scanner;
import java.util.*;
public class Pool
{
private String poolshape1 = "oblong";
private String poolshape1 = "rectangle";
private double length;
private double width;
private double depth;
private static double GallonsPerSqFoot = 7.4805;

[Code] .....

View Replies View Related

Cardlayout Format - Change Main Menu Screen Into Game Screen On Button Click

Mar 16, 2015

I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so

Here is the code from my CardLayout:

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;

[Code] ....

I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.

Here is the main important GUI from my CheckerBoard class:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
  public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
 
[Code] ....

Once again kept to a minimal.

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

JavaFX 2.0 :: HTMLEditor - Default Size / Cannot Fill Full Screen

May 10, 2015

The code:
 
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;

[Code] ....
 
run (when window height > 700px ) :
 
HTMLEditor  default height is 670px, the other area (green color) is not filled,why?
 
HTMLEditor   高度总是670px, 怎么把HTMLEditor 填充满窗口?
 
这是一个bug吗?

is it bug?

View Replies View Related

Program To Change Colors Of A Shape In Other Window

Feb 13, 2015

I was working on this project, and I have everything working, except that it doesn't change the colors of the shapes in the other window. Here's the code to see what I'm doing wrong:

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JDemo {
//Global Variables
static Color color0 = Color.blue; //sets the value in the color0 variable to the method Color.blue .
static Color color1 = Color.red; //Sets the value in the color1 variable to the method Color.red .

[Code] ....

The button0 is supposed to switch the color in window1, and button1 is supposed to switch the color in window0.

View Replies View Related

Implementing Classes Instead Of Extending To Get Methods?

Sep 20, 2014

Basically I want to make a class called library, but I don't want to make an interface because I actually want to define the methods. I think I can only use abstract classes but not really sure how to use those. But I still have a problem, I want to create a Map that classes implementing Library class have to have in their code, and the Map will be a HashMap with <String, ParentClassHere>, so basically let's say I make a class called Car, implemeing Library to the Car class would create a Map library = new HashMap<String, Car>. Can I do something like this? And also include methods to get values and set values to the library Map?

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

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

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

Swing/AWT/SWT :: Change The Blue Color?

Apr 6, 2014

When I click a JButton, it will become blue momentarily. Is it possible to change the blue color? If yes, how?

View Replies View Related

Swing/AWT/SWT :: How To Change Jbutton Color While It Is In Focus

Jan 27, 2013

refer to this code~

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change Background Color Of Panel

May 3, 2014

Program is not working. I want to use buttonPanel object in ColorAction class and the process is unknown to me .

package button;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ButtonFrame extends JFrame
{
public JPanel buttonPanel;

[Code]...

View Replies View Related

JSP :: Change Color Of HTML Table Row In A Page

Aug 28, 2014

I am creating a JSP page with a html table to display employee directory. This is scriptlet :

<%
List<Employee> list = new ArrayList<Employee>();
PhoneListController controller = new PhoneListController();
list = controller.getAllContacts();
for (Employee eachEmp : list) {
%>

and then i display the table rows and columns for each employee object(PS: I know scriptlets are bad and obsolete but this is my first individual project.)

I would like to change the background color of certain rows based on value of one particular value(based on eachEmp.getManagerCode).

How can i achieve that by using javascript? I tried to call a js function by calling onload event on . But as I need to check for each row that is not the possible solution. I have not tried jquery yet as I am very new to jquery and I didnt quite understand how to do it in jquery.

View Replies View Related

JRadio Buttons To Change Font Color In Code

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

How To Change Color Of Column Header When Cell Is Clicked

Jan 21, 2015

I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?

private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);

[Code] ......

View Replies View Related

Swing/AWT/SWT :: Change Content Pane Color Of JFilechooser

Mar 25, 2015

I'm dealing with, change the content pane color of jFilechooser. Color has been changed but the problem is when I open the subdirectory leads errors; Note : It also trigger error when I set default directory; like chooser.setCurrentDirectory(file);

The following error is the result:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:912)
at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:961)
at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:888)
at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:94)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:239)

[Code]...

Following is the code base

import javax.swing.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

[Code]...

View Replies View Related

JavaFX 2.0 :: Change Arrow Color On Header Of TableView

May 20, 2014

is possibile to change the color of the sorting arrow that appears in the columns of the Table View by css? My attempts have failed and I have not found any documentation, nor is there any reference in the Modena css.

View Replies View Related

JavaFX 2.0 :: Dynamically Change CSS Class And Splash Screen Implementation

Jan 12, 2015

So it seems to reason that many JavaFX applications will want to dynamically change CSS styles.  Is the best way to do this via the <node>.getStyleClass().add("classname")?  The underlying data structure is an observable list.  So lets say one has 5 styles that simply change the fill color of a circle to 5 different colors respectively.  So if I have a condition in which I want to dynamically apply 1 of these 5 styles, the way I currently do this is by defining all 5 styles as strings in a list using a static initializer, then I call <node>.getStyleClass().removeAll(list), then getStyleClass().add("classname").  I do this to avoid adding the same style over and over and inflating the underlying list.  Is this the correct way to manage dynamic CSS styles?
 
So I know there is a few different way to implement a splash screen.  My app has definitely gotten larger over the last few months of development and I have noticed there is about a 5 second delay between when I run the application to when I see the main stage.  I was thinking a splash screen would be nice to fill this time period.  I have not had time to prototype using a Preloader and I fear that using an alternate, lightweight stage on startup would still take too long of a delay.  I was actually thinking that using the nice and simple JVM argument "-splash:<image name>" would be simple, easy and effective.  Unfortunately when I try to do this, the splash screen comes up but never goes away. 

View Replies View Related

Change Type / Custom Color Of Rectangle Made Through DragMode

Jun 9, 2014

What I'm trying to do is basically draw a Rectangle outline through left-click and then dragging the mouse to the size one wants.

After one has created this rectangle, the user can change the color of the rectangle through clicking the 3 sliders found on the top in the program. Upon the change in color, the rectangle should change from "g.drawRect" to "g.fillRect" and use the desired color.

I have the basic outline of the program done, but working with the last part (the color and changing of the Rectangle type after changing the color)

Is there like a "then" command in Java? Like: after you've done x, do y. That would make this heaps easier.

import java.awt.event.*;
import java.awt.*;
import java.applet.*;
 
//Diese Applikation offnet ein Fenster,
//in welchem durch einen gehaltenen linken Mouse Klick
//ein Reckteck gezeichnet wird
 
public class WhatIsTheProblem006 extends Applet
implements AdjustmentListener {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change Color Of Column Header When Cell Is Clicked In JTable

Jan 20, 2015

I'm working on a spreadsheet-like table and I was able to set it so that it would highlight the first cell in the relevant row(titled 1,2,3.. etc) when a cell is clicked. (Just like in MS Excel - preview attached) Now I want to do the same to the column header(i.e. A,B,C,D....etc) . How can I do it?

private void formWindowOpened(java.awt.event.WindowEvent evt) {
setLocationRelativeTo(null);
int rowNum = sheet.getRowCount();
for(int i=0; i<rowNum; i++){
sheet.setValueAt(i+1, i, 0);

[Code] .....

Untitled.jpg

View Replies View Related

Most Efficient Way To Store Color Effect Methods To Be Used

Oct 18, 2014

This isn't solely related to java.awt.Color, it's more of a question on how to store methods or redirections to use methods on any value passed in. To explain my question I'll describe a scenario:

ClassA is an instanstiatable class

ClassA has an instance of ClassB called cB

ClassA has methods of affecting cB

ClassD is also an instanstiatable class

ClassD has an Array[x][y] of instances of ClassA

I want to create a ClassE which I would initiate it with references to ClassA's methods or their actual methods and then I can use ClassE to easily transform ClassD's instances of ClassA by the same methods.

What I'm actually doing:

I made a class called GameColor, it has methods like changeHue, setRed, setHue, changeBrightness, setSaturation etc, these methods affect an instance of java.awt.Color in the GameColor class instances, so like they can change the hue or set it with changeHue or setHue etc...

Now I want to do something like perform a single method on a whole BufferedImage, on each of it's pixels RGB. So, I'm thinking of creating a GameColorEffects class which I store references or actual methods of GameColor like changeHue, and then I use GameColorEffects somehow to change a whole BufferedImage more efficiently, what's the most efficient way I can store methods or their reference of GameColor and then later apply them on each pixel of a BufferedImage using GameColorEffects. So all I do is initiate GameColorEffects with methods or reference from GameColor, and then I can apply it to easily transform each pixel.

View Replies View Related

Java Program That Draws A Spiral?

Nov 7, 2014

I'm trying to make a java program that draws a spiral like this: [URL] ....

It was use a draw method to draw it in a specific way. What I have in my code so far is:

for (int i=0; i<line.length; i++) {
line[i] = new int[4];
line[0].x = 0; line[0].y = 0;
line[1].x = 0; line[1].y = boxSize;
line[2].x = boxSize;line[2].y = boxSize;
line[3].x = boxSize;line[3].y = 0;

It would be made through a 2d array and the values for how big the lines are would be stored in another file called line_details.txt which contains these values 0 200 1 175. So how would I implement this stuff into a Java code?

View Replies View Related







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