How To Make 2 Rectangles In Same Window

Oct 2, 2014

My goal is to make 2 rectangles in the same window. so far I have this.

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
public class BoxComponent extends JComponent

[Code] ....

After running the program I get one rectangle, the red one. If I take the code out for the red rectangle, I only get 1 blue one. What am I missing?

View Replies


ADVERTISEMENT

Make GUI Window Bigger

Apr 21, 2015

I have the following problem:I have 4 components in my GUI that goes like this in the CENTER of the BORDERLAYOUT:

1. JLabel

2. JTextArea

3. Jlabel

4. JTextArea

Everytime i make the GUI window bigger, all these elements spread out. How can i get these elements to have a BREAK line (i.e. a break line after 1. Jlabel) so that no matter how i stretch the window, it will stay in-tact and the other elements will follow underneath.

View Replies View Related

How To Make Image Background For A Window

Jun 17, 2014

I would like to learn how to add an image background to a window in java that I can put controls like buttons, textboxes, and checkboxes in front of. I already tried using a JLabel with an ImageIcon but I cannot overlay controls over the JLabel. From what I understand there are multiple ways to do this. What is the best way and how can I do it?

View Replies View Related

How To Make JCreator Output In Command Window

Aug 30, 2014

I set these up, but the command console comes up, I don't see the "Hello World" in the window and it closes.

How can I get the output "Hello World!" to appear in a "cmd" window and stay there till i close it?

View Replies View Related

How To Make Jar File Compatible For All Window Machines

May 5, 2014

I made the program below in java and compiled with javac command in Window7 (64bit machine). It simply post my machine IP and Mac address to my server application.

When i run this script with java as >java Macregister

I get what is expected, the program runs well on my machine.

When I try to run it on other machines (Win8 - 32 Bit) I get error message and nothing works.

My problem is 1) to make it compatible for all machines 2) to convert it into JAR application so that it is self executable on different machines.

I am a new to Java and am struct,

import java.net.*;
import java.io.*;
public class Macregister{
public static void main(String[] args) throws Exception {
InetAddress add=InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(add);
byte[] mac = network.getHardwareAddress();
StringBuilder sb = new StringBuilder();

[Code]...

View Replies View Related

How To Make Picture Appear In Same Window As The Rest Of Drawings

Feb 12, 2014

I am trying to learn Java and while i was playing a bit with the basic knowledge that i have i encountered a problem. When i run the program, the lines and the picture appear in two separate windows when i compile the program. how can i make them appear in the same? The code is this:

public class Game

private int x;
private Picture pic;

[Code].....

View Replies View Related

JavaFX 2.0 :: Manipulating Several Windows (Window Inside Window)

Apr 6, 2015

I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.

I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.

View Replies View Related

Two Rectangles Overlap

Oct 27, 2014

the thing with this program is that instead of it having preset variables, I want to prompt the user to enter values of the two rectangles. I don't know how to use the scanner in this case, or even if I should use the scanner.

class MyRectangle2D {
//declare the variables
private double x, y;
private double width, height;

[code]...

View Replies View Related

Determine If Rectangles Cover Each Other

Oct 22, 2014

[URL] .... This is a link to the credentials that need to be met.

/* Constructors, getters and setters that will determine if the rectangles cover each other.*/

import java.util.Random;
import java.lang.Math.*;
class Rectangle{
   int width = 50;
   int length = 50;
   int x = 90;
   int y = 90;
  
[Code] ....

View Replies View Related

Drawing Rectangles From Array List

Nov 13, 2014

The program is where you will click anywhere in the jframe and it will draw a new rectangle. I have altered the code given to us but the problem that I am having is the fact that when I click the rectangle will always be connected to the upper left hand part of the jframe, no matter where I click. The program should create rectangles of the same length and width wherever you click. Here is what I have. I believe I have to change something in the addRectangle method, but nothing that I have tried works.

Java Code:

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
import java.util.ArrayList;
public class RectangleComponent2 extends JComponent

[Code] .....

View Replies View Related

Collision Detection Using Rectangles - Player Sometimes Passes Through The Tiles

May 19, 2014

I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.

private void movement(){
left=bindObject.getLeft();
right=bindObject.getRight();
up=bindObject.getUp();
down=bindObject.getDown();
bindObject.setColliding(colliding);

[Code] .....

Where bindObject is a class which contains key bindings of following keys:-

left arrow key (when pressed) , left arrow key (when released),
right arrow key (when pressed), right arrow key (when released),
up arrow key (when pressed), up arrow key (when released),
down arrow key (when pressed), down arrow key (when released)

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

Draw 3 Rectangles In Different Spots / Move Elements In Order So They Do Not Cross

Apr 9, 2014

I made a small aplication which draws 3 rectangles in different spots(0,0 , 50,50 , 100,100)

Am I used an KeyListener + ActionListener, to make them move in the let's call it box.

How can I do in order that those 3 elements do not cross, so you can always see them, they don't collapse into each other?

Java Code:

package matrixmoveelements;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

[Code] ......

View Replies View Related

Display And Resize Multiple Rectangles Independently - Using Objects From ArrayList

Jan 13, 2014

I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).

Resizing component;      boolean dragging = false;      // Give user some leeway for selections.     
final int PROX_DIST = 3;      Path2D.Double selectedPath;        public Resizer(Resizing rz) {         
component = rz;          component.addMouseListener(this);         
component.addMouseMotionListener(this);     

[Code] .....

View Replies View Related

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 View Related

2D Tile Game Lag (Caused By Loop) - Rendering All Tile Rectangles

Jan 18, 2014

So the following is my code for the Terrian Generation of my game, however the way i have it rendering all the tile rectangles as opposed to just rendering whats visable on my JFrame causes lots of lag.

These are the variables and Rectangles inside _TerrianGen.class

//CHUNK
static int chunkx =2048;
static int chunky =2048;
 
//RECTANGLES
public static Rectangle[][] tile = new Rectangle[64][64];
static int[][] blockType = new int[64][64];
//0=Grass 1=Dirt 2=Stone 10=Brick 11=Coal 12=Iron 21=Gold 22=Diamond -1=null

This is the Init() code

for (int x =0; x < chunkx-32; x+=32){
for (int y=0; y < chunky-32; y+=32){
tile[y/32][x/32] = new Rectangle(x, y, 32, 32);
blockType[y/32][x/32] = -1;

[Code] ....

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

Swing/AWT/SWT :: Simplest Window Possible

Feb 5, 2014

Is it possible to display an AWT Window only(just 'cause feel like doing it)? Or, is the simplest window possible to display a JFrame?

View Replies View Related

How To Specify Location Of Opened Window

May 8, 2014

I am writing a small app to automate some actions on my computer this requires me to open an application and click on a button I am using

Process child0 = Runtime.getRuntime().exec("/home/user/application");

to do this. The problem is every time it opens at a different lcation on the screen so i cannot click on it using the robot class due to x,y coordinates being different every time. with selenium you can use .setlocation(x,y) method but how can this be done for other applications.

View Replies View Related

Can't Create A 100x100px Window

Apr 19, 2015

I have an assignment to create a circle with a radius of 40px in a 100px by 100px window and move the circle with the arrow keys.The circle can't move past the the edges of the window. I believe I have the code right but the window won't create the window or pane with a width of 100 px because of the close, minimize, maximize buttons. Is there a way to remove those or force JavaFX to create it with a width of 100px? Here's what I've got so far.

package movecircle;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

[code]....

View Replies View Related

Making Window Not Resizable

Oct 9, 2014

How would i go about making this NOT resizable?

If I do try to do ChatFrame.setResizable(false); it gives me this error:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
Cannot make a static reference to the non-static method setResizable(boolean) from the type Frame

at com.ui.ChatFrame.<init>(ChatFrame.java:37)
at com.ui.ChatFrame$5.run(ChatFrame.java:403)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)

[Code] ....

Here is the code:

package com.ui;
import com.socket.History;
import com.socket.Message;
import com.socket.SocketClient;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

[Code] ....

View Replies View Related

Window Closing Event

May 20, 2014

I have a WindowClosing(WindowEvent e) method, but when I close my window it isn't doing anything inside the method. I am making a launcher and I want to make it so when the actual game window is closed it makes the launcher window visible again.

Java Code: public void windowClosing(WindowEvent e) {
this.jf.setVisible(true);
} mh_sh_highlight_all('java');

View Replies View Related

Swing/AWT/SWT :: Displaying PNG In A Window

Jan 31, 2014

That's my third day working in Java using Swing and the IntelliJ Idea IDE.I'm trying to do something as simple as displaying a PNG in a window, and I'm doing this:

public class AboutRapide {
public JPanel mainPanel;
private void createUIComponents() {
mainPanel = new ImagePanel();

[cod]....

the problem is that, in the paintComponent method, the Image is never found when I run my app from the IDE, but it is when I run it from Finder in my Mac. Same application. I think it relates to how the application is launched so I guess what's a proper way to refer to a resource file with an image so it can be displayed no matter how the application is launched?Also if I generate a Jar for the application, as the resource gets into the Jar compressed file, it can't also be loaded.

View Replies View Related

Repaint Window From Another Class?

Mar 31, 2014

I am trying to repaint a window from another class. the class Window handles an interface that displays pictures of movies. Via a JMenuBar you can add a new movie and its picture but in order for it to show in the Window i need to repaint certain aspects in the Window class GUI;

The window class constructor:

public Window() {
addComponents();
configurFrame();
addMenu();
}

The functions i want to repaint:

public void repaintWindow() {
this.getContentPane().validate();
this.getContentPane().repaint();
}

From my other class where i add a movie to an ArrayList i have made a "private Window myWindow;" there i call the function repaintWindow via mywindow.repaintWindow(); But this gives me an NullPointerException related to the repaintWindow function.

View Replies View Related

Resize Window To See Programs

Jan 21, 2014

Whenever I make something in Swing, I always need to resize the window for me to see the graphics on the window. I have been told to use the pack() method on it, which I have, but the problem with it is that it just sets the window to a minimal size, only displaying the x + and -.For one of the "games" I made, it at first didn't work until resize, then I added a repaint() after the constructor and it worked for me, but when my friends download it they cannot see it.

View Replies View Related

Java Frame Window Using Button

Jan 21, 2014

How one frame to another frame using button ?

View Replies View Related







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