Swing/AWT/SWT :: Mini Paint Program - Changing Size Of Shapes

Jun 4, 2014

I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.

So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.

This is the minidraw class

import ecs100.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.JColorChooser;

[Code] .....

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Paint Screen Without Paint Methods?

Sep 22, 2014

Is it possible to paint to the screen without using methods such as paint(), paintBorder(), paintChildren, paintBorder, paintComponent, paintAll() and any other paint like methods I may have missed. These are, by the way, taken both from JComponent and Component. So, is it possible?

View Replies View Related

Client-Server Mini Program Is Not Communicating Right - Blocking Read Line Does Not Block?

Feb 3, 2014

Me and my brother decided to make a relatively simple client/server program where clients get into a simple chat lobby and can invite others to play small games(like pong). The basic server code has been written, and we have made a special client that is used for debugging.

We use a self-defined protocol of Strings where a message looks like "4-|user,pass". The number before the delimiter "-|" is the operation code, that tells the server what kind of message this client sends. Based on that number, the server dispatches the message to the appropriate handler method. 4 is authentication for example, and the handler looks the user and pass up in a file and if found, returns true, otherwise, false. Then the server responds to the clinet with 2-|"any message" where the client will recognize opcode 2 as a "authentication accepted" and proceed with the next part of client code. In a similar way, we plan to write all message types(both in the game, in the lobby and in a game setup room).

While testing we ran into a problem where the BufferedReader .readLine() does not seem to be a blocking call like it should be, so the client keeps spamming 'null' in the output field that we made to see the server response to the message we send. When we try to debug the server code and set breakpoints at the suspicious locations, it strangely skips both while(true) loops without activating either breakpoint and executes the finally{} code, even though the client did not close the connection and the second while loop was never entered. The first while loop IS entered though, because the test client gets a "0" on its output, which is the server message indicating "please authenticate yourself".

We decided to use messages in a string format and decode it at both sides as it seemed easier than transmitting java objects and making sure they are of the same type, also for reducing overhead as much of possible.URL....

package Chatroom;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;

[code]....

View Replies View Related

Java Code - Changing Text Size In Windows Settings

Apr 14, 2014

I have a major problem. the text size is like 6 or 8 pt font and I can't read it. I'm trying to run a downloaded exe program which uses the jre7 which I had to download beforehand. the font size stays at 6 or 8 even if I try to change it in windows settings. it's a high res monitor on a lenovo yoga laptop. is there a way for me to edit the java code and manually change the font size?

View Replies View Related

Part Of Panel Missing - No Code Error (tried Changing Size)

Apr 20, 2014

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.*;

public class aaa extends JFrame
{
private JPanel combinationp, np, ap, dp, surgeryp, medicationp, infop; // input = name, address, days
private JLabel namelabel, addresslabel, dayslabel, infolabel;
private JTextField nametf, addresstf, daystf, selectedsurgerytf;
private JButton calcButton;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Drawing Various Shapes - Repaint Not Working

Jan 16, 2015

I'm trying to make a simple program that will feature some graphics. It will have a JCombobox that the user selects to draw various shapes. I can't get the repaint function to work however.

package selectingshapes;
import java.awt.Graphics;
import java.awt.Color;
import javax.swing.JPanel;
import java.awt.Graphics2D;

[Code] .....

View Replies View Related

How To Make Paint Program Not Error Out

Oct 14, 2013

I am screwing around with mouse listeners so i decided to make a basic paint program. It works fine but when it draws more than 100 circles it errors out. i know why its doing it (its because i set the array to 100) but my question is how to make it so it has not limit in the array.

Here is the code

public class PaintProject extends Applet {
int numClicks = 100;
int numCicles;
int xCoord[];
int yCoord[];
boolean paint;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Paint Image On Frame

Mar 8, 2015

I simply want to paint an image on my frame, just once each time the paint() method is called, but how to call the paint method in any good way. This is how it looks:

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

[Code] ....

I have a frame in another class, and from my assumption I need to somehow tell my paint method to paint on that specific frame right?

View Replies View Related

Swing/AWT/SWT :: How Much Overhead Involved In Associated Paint Methods

Jan 27, 2014

Since the Paint methods are being executed anytime a frame is being moved or resized, how much overhead could an application incur if the application

- has many frames
- doing a lot of moving
- doing a lot of resizing
- has a lot of background processes running.

As a rule, I try to only keep the most essential code in these types of methods and wondering if that type of thinking is "old school".

How much overhead is actually involved? If you needed to monitor the size of a given frame anytime the user resizes it, would you be concerned that using these methods would incur too much overhead?

View Replies View Related

Swing/AWT/SWT :: Paint Application - Mouse Events In Same Class

Apr 15, 2015

I have my paint application, i use the following mouse event to draw my shapes (mousePressed, mouseReleased, mouseDragged). Now after the user paint a circle for example, he must be able to drag the shape; to be able to do this. i think i must again implement the different mouse Events. I have done it and the drag is not working. How can i achieve this. can we implement multiple (mousePressed, mouseReleased, mouseDragged) in the same java class??

View Replies View Related

Swing/AWT/SWT :: Keeping Track Of Strings Drawn On JPanel Using Paint

Nov 1, 2014

So, I have this simple program that paints a string on JPanel using g2.drawString("Hello world", 40, 120). Basically, I want to be able to keep track of many strings on the JPanel at once. I'm not sure how to do this. For example, I would want to have an ArrayList of objects that keep track of these strings.

I want to be able to click-and-drag these strings so I will need to know there locations, etc.

Right now, using g2.drawString, it only draws the string. I want something like gw.draw(myStringObject).

import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Paint Circle In Frame On Key Press - Cannot Get KeyListener To Work

Nov 3, 2014

I wanted to try out using a KeyListener to read what key I press so it can paint a circle in my frame, but I can't get it to work?

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;

[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

Changing JLabel Text From Anywhere In Program

Feb 18, 2014

I'm using NetBeans.

I have a JFrame with four JPanels, SensorLL, SensorLC, SensorCR and SensorRR. They are instances of the class SensorUI. Each has a JLabel called Sensor.

The class SensorUI has a method writeSensor that writes to the JLabel "Sensor". I will have four temperature sensors. I have not started the code to read the temperature sensors yet. I will have a timer that will run once a second. When it fires I will read the sensors and display the result in the

JLabel "Sensor" in each jPanel.

I use MyMain to call FrameDemo and create the JFrame and a method

in FrameDemo to add the JPanels using addObject.

I can use SensorLL.writeSensor will write text to JLabel Sensor while in Mymain.

Then I start the timer ReadSensor.

When it times out it calls SampleSensors

For an experiment, while in SampleSensors I try to write to the JLabel in the instance SensorLL with

SensorLL.writeSensor("xx_");

I can't because it says it can't find the symbol variable SensorLL in SampleSensors class.

How can I "get to" that JLabel text when ever I need to?

Java Code:

public class MyMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//SensorUI SensorLL = null;
System.out.println("Start of main");
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
FrameDemo.createAndShowGUI();

[Code] .......

View Replies View Related

Swing/AWT/SWT :: Label Font Not Changing?

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

How To Write Mini Sudoku In 4x4 Puzzle Using Java

Oct 31, 2014

How to write a mini sudoku in 4x4 puzzle using java The entries of each grid are 1,2,3 or 4 only.

No number will be the on a row.

No number will be the same in a column.

There are 4 regions in the puzzle and no number will be the same in a region.

I want to ask how to finish the below code, because I don't know how to extend using the below code

import java.util.*; 
public class MiniSudoku {
 final static int SIZE=4;

[Code]....

View Replies View Related

Swing/AWT/SWT :: Changing Rectangle Color With MouseListener

Mar 2, 2014

I'm trying to build a program which sets a fill color for a rectangle. Each time the mouse is clicked the fill color changes according to the position of the mouse's X and Y. I succeeded to create a JFrame with a changing background according to the Mouse's position, but I can't seem to change the color of the rectangle (defined in MyPanel class).

This is the current code,

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;

[Code]...

View Replies View Related

Swing/AWT/SWT :: Changing Canvas Returns With NullPointerException

Jun 22, 2014

I'm currently having trouble with a Breakout clone that I'm working on when I want to change the scenes of the game. When I start out with the main menu and I hit play, the main menu calls for the StateManager to remove the MainMenu and then to add the GameState to start playing through the levels. But, whenever this is done it just gives a NullPointerException and freezes the game. I know the code for initially starting a State is fine because that is the same way the MainMenu is loaded but there seems to be an issue with changing from one to another...

This is the StateManager class that adds and removes the States/Canvases to and from the JFrame/Main class:
package com.pathtocreating.Breakout_V2.state;

import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.JFrame;
public class StateManager {
private ArrayList<State> states;

[Code] ....

The code that calls the change of state in MainMenuState is called in the update method:

if(inputController.isMouseClicked("LeftClick")) {
if(playHover) {
soundManager.playSound("ButtonClick");
BreakoutMain.sm.changeStates("GameState");

[Code] ....

Here is the full stack trace when clicking the area to change states:

Exception in thread "Thread-2" java.lang.NullPointerException
at sun.java2d.SunGraphics2D.validateColor(Unknown Source)
at sun.java2d.SunGraphics2D.<init>(Unknown Source)
at sun.awt.image.SunVolatileImage.createGraphics(Unknown Source)

[Code] ...

It gives that same value both before and after clicking on the region.

Printing out b after the State is changed to GameState gives the following:

java.awt.Component$BltSubRegionBufferStrategy@66116674

I've tried messing around with the order of which things are added/loading from the StateManager but am just failing to see what I did wrong.

View Replies View Related

Swing/AWT/SWT :: Changing Color Of JList Item

Oct 23, 2014

is there a good way to change the color of a JList item that isn't selected? I'm throwing my hand at building a client/server chat app and on the client side, I need to highlight the name of the person (which is in a JList) who has sent a message to the client GUI.

View Replies View Related

Swing/AWT/SWT :: Changing Text Of JLabel From Another Class

May 26, 2014

Create a dnd (dungeons and dragons) character creator and back ground generator, have it display and run on a gui, to start with i decided to creator the gui as i go so i can see the progress, first i tried eclipse and windows builder, well after 1 day of reinstalling windows builder in about 5 different ways from multiple guides and sometimes getting it to partly work ...

After doing some more research I have figured out how to get the main program to display the gui . Heres what i have:

package com.mrgreaper;
import javax.swing.*;
public class MainWindow {
private JPanel mainWindow;
private JLabel playerlbl;
private JLabel playerNamelbl;

[Code] .....

Now this works fine and the gui displays when the program is run but I can't change the text of any of the jlabels or textfield. If I try to do it in the main class i need to change them from private to public static but then in the form builder it says "cannot bind to static field *name of field*" but if i take static off then i cant change its value!

From what i understand this is because the window is an instance, so how to i change the value in that instance? I could put all my code in the one class, the one that creates the gui, but i really want it seperate, i would like the gui to update as the code runs... So how do i do it, how do i change the contents of jlabels on the fly, read the contents of text boxes on the fly etc....

I tried adding a getter setter

public void setCharFirst(JLabel charFirst) {
this.charFirst = charFirst;
}
in the MainWindow.class

Then i tried to set it from my main function

MainWindow.setCharFirst("test");

but it cant access it as my main function is static and it is not now can i make it static...

View Replies View Related

Personality Test Program Not Changing Array Values

Apr 1, 2014

I'm making a program for school that reads a text file with answers to a personality test and prints the temperament to an output file. Problem is, it sets the temperament for the first person to INFJ and then prints INFJ for the rest of the people too. My code is below, and the input file 'personality.txt' goes like this:

Betty Boop
BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA
Snoopy
AABBAABBBBBABABAAAAABABBAABBAAAABBBAAABAABAABABAAAABAABBBBAAABBAABABBB
Bugs Bunny

[Code] ....

This is my Code :

public static void main(String[] args) throws FileNotFoundException {
welcome();
Scanner input = new Scanner(new File("personality.txt"));
PrintStream out = new PrintStream(new File("output.txt"));
int[][] outcome = new int[4][2];
double[] percent = new double[4];

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Setting Size Of JFrame

May 26, 2014

I am rather new to Swing, and I am building a game right now in which I need to display a pop-up window as a reminder for what commands exist within the game. I created a class extending JFrame for this and added all the information I need. However, for some reason, no matter how many different ways I try to set the size of this window (setSize(w, h), pack(), using a different layout, adding the compnents to a JPanel first and setting the preffered size of that, then adding the JPanel to the JFrame), it doesn't work. Instead of a window of my requested size, I get a tiny, maybe 100 x 100 pixel window that needs to be resized in order for its contents to be visible.

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

[code]....

View Replies View Related

Swing/AWT/SWT :: Adjusting Size Of Box With Mouse

Oct 16, 2014

I'm running the code below which compiles ok using latest version of Java and on Sublime. The problem when it complies the output screen is blank and I can only see the text by adjusting the size of the box with my mouse - and then it colours in black. Code and screenshot below. Is there something wrong with the paint/graf part of the code?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class BackArray extends JFrame {
int store[] = {2,6,4,8,34,67,19,99,10,12,89,68,45,37};
int xcoord = 100;
boolean firsttime=true;

[code]....

View Replies View Related

Swing/AWT/SWT :: Change Size Of Entire GUI?

Feb 4, 2015

I built a GUI and after testing it on various platforms I think I would like to make it bigger by a factor of 2.2 or so.

Is there an easy way to just enter the factor 2.2 and have the GUI change by that factor?

I have over 50 components in the GUI. Ideally each one would just enlarge by the factor including the fonts.

This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code.

View Replies View Related

Swing/AWT/SWT :: Screen Resolution / Size

Sep 29, 2014

I have created a java gui on Windows 7 with Eclipse EE, using a screen resolution of 1366 x 768. I used groups with specified boundaries. For example:

final Group g5_script_data = new Group(shell, SWT.BORDER_SOLID);
g5_script_data.setText("Current DB");
g5_script_data.setBounds(0, 0, 680, 380);
g5_script_data.setBackground(green);

The groups cover the whole screen.

However my colleague with a smaller resolution looses the far right of the screen.

As this is a proto-type and I'm new to Java I don't want to rework everything or convert it to say a grid layout until the proto-type is accepted and I can start from scratch with a real detailed design. It already has 6500 lines of source.

Just wondered what is my quickest/easiest way to get my app to display on a slightly smaller resolution. For sure it will not be anything silly. Something like 1280 x 768 to 1366 x 768 would do.

View Replies View Related

Swing/AWT/SWT :: How To Change JFrame Size

Jan 14, 2015

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code].....

View Replies View Related







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