Swing/AWT/SWT :: Application That Displays A Frame Containing Two Panels

May 9, 2014

I'm having trouble with this program. In my textbook it says "Write an application that displays a frame containing two panels. Each panel should contain two images (use four unique images - your choice). Fix the size of the first panel so that both of its images remain side by side. Allow the other panel to change size as needed. Experiment with the size of the window to see the images change orientation. Make sure you understand why the application behaves as it does". I successfully imported the images, but I can't find out anywhere how to allow the second panel to change size with the window.

import java.awt.*;
import javax.swing.*;
public class TwoPanels
{
public static void main(String[] args)
{
JFrame frame = new JFrame ("Embedded Images");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon iconOne = new ImageIcon ("glove.jpg");
ImageIcon iconTwo = new ImageIcon ("cleats.jpg");
ImageIcon iconThr = new ImageIcon ("bat.jpg");
ImageIcon iconFou = new ImageIcon ("baseball.jpg");

[code]...

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Need To Draw JButton Such That It Displays On Top Of Two Different Panels

Mar 3, 2015

one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.

View Replies View Related

Swing/AWT/SWT :: Frame And Panels

Nov 30, 2014

I wrote the following code to get a frame,button in south and a red color circle,which i got.In the "actionPerformed" method i wrote "setContentPane(mp2)" thinking it would put another panel on the frame with a blue circle but when i pushed the button,the button got stuck and the circled did not change.

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Fra implements ActionListener
{
MyPanel2 mp2;
JFrame frame;
JButton button;
public static void main(String[] args)

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Panels Switching On A Single Frame Using Netbeans Builder

Feb 3, 2014

I am writing a ComputerBaseTest application with Netbeans. I have each question on a panel and I want the questions(panels) to be switched, viewing the previous and the next question on a single frame, but I do not know how.

I only understand frame switching if each questn is to be on a frame but each score on each question (frame) do not sum up to give the overall score at the end of the test. Using multi-frame shows a sign of bad programming.

View Replies View Related

Swing/AWT/SWT :: How To Prompt Before Exit In Single Frame Application

Apr 22, 2014

I have a Single Frame Application and I simply want to prompt the user with a dialog confirming they really want to close before they actually close the program, specifically when they click the X in the upper right. I THOUGHT it was like any other java application, with the slight added complexity of having to target the program-created-JFrame with: ".getApplication().getMainFrame()".

MyApp.getApplication().getMainFrame().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

With that code, DO_NOTHING_ON_CLOSE is set on the JFrame, yet the program closes anyways. Which I don't understand.So I did some reading and found this: URL....That lead me to the configureWindow override, where I successfully tried this:

root.addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
// write your code here
System.out.println("Window Closing");
}
});

But as far as I can tell that will only let me react to the window closing, not to the command to close it, where I could then kill the command in the dialog if they so "no I'm not ready to quit yet", if that makes sense. So, how to give a prompt before closing?I am using netbeans IDE to create this app - not sure if that is relevant, since maybe it is an oddity with the IDE and not Single Frame Applications.

View Replies View Related

Java Application That Displays Composite Numbers?

Dec 31, 2014

I am trying to write a java application that displays composite numbers between 1 and 100. Here is the format of my code:

//a java application that prints out composite numbers that range from 1 to 100 
public class printcomposites{ 
public static void main(String[] args){ 
int num=0;
 int i=0;
 String printcomposites=""; 
for(i=1; i<100; i++)

[code]...

My code compiles with no errors, but my code generates every integer between 1 and 100 instead of integers that are composite:

Composite numbers from 1 to 100 are:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 5
7 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

What am I doing incorrectly?

View Replies View Related

Swing/AWT/SWT :: Cannot Get Panels To Appear In GUI When To Run Program

Mar 25, 2014

I cannot get my panels to appear in my GUI when I run my program. There is probably a really simple fix for this but it is taking me hours. This program is a working progress and I have just included two classes out of five. That should be adequate to diag my problem.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class OrderCalc extends JFrame
{
private final int WINDOW_WIDTH = 200;
private final int WINDOW_HEIGHT = 200;

[Code]...

View Replies View Related

Swing/AWT/SWT :: JFrame Using Layered Panels With MigLayout

May 23, 2014

The question is when I hit the maximize button on the JFrame my panel instantly goes to the top left corner of the JFrame. Is it possible to center the panel inside the JFrame, when the maximize button is pushed? I am familiar with push and grow that MigLayout uses but this isn't exactly what I need. I don't want several textFields to span the screen. Instead I would rather have the panel centered.

This is just a sample project to test out the MigLayout API

View Replies View Related

Swing/AWT/SWT :: Creating Inner Class For Layered Panels

Apr 29, 2014

Is it good practice to create a inner class for layered panels with lots of components? In my opinion this makes the code easier to read and a lot less clustered.

View Replies View Related

Swing/AWT/SWT :: CardLayout Switching Panels On Click Of Button

Jun 19, 2014

I am trying to switch panel on click of a button but nothing is happening.

package game.uno.swings;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;

[Code] ....

I read the oracle doc example, i understand the concept but still nothing is happening on show,first ,next method of CardLayout in ActionPerformed. Code is highlighted where I am facing problem.

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 :: Java Frame Is Showing Blank?

Jul 5, 2014

i have problem with the following two java classes, driver class Reservations and Room class. When i run, it just show blank frame, tell me where i gone wrong.

import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
public class Reservations extends Frame implements ActionListener {
Color lightRed=new Color(255,90,90);
Color lightGreen=new Color(140,215,40);
Rooms room=new Rooms(5,3);

[code]...

View Replies View Related

How To Avoid Flickering When Calling Another Swing Frame

Jul 28, 2014

I am trying to call another swing frame from my current frame. And after calling second frame i dispose the current frame.

But while second frame coming on the screen, current frame gets dispose and second frame takes some seconds to appear on screen.

So its creating a bad flickering effect on screen and its not suitable for my application.

I want that first frame will call sencond frame and it will not look like second frame is called. I just want to cancel flickering effect.

Here is my source code.

1st Frame:

public class Welcome extends JFrame {
JFrame f;
JTextArea nameField,nameField1;
JLabel lable;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Jinternalframe Active Frame Different With Java 7?

Jun 24, 2014

I am in the progress of updating my code and re-testing after switching from Java 6 to Java 7. When I open multiple JInternalFrames in my application under java 6 I am used to closing the top most internal frame and having the frame immediately under it become the next active frame. When I run the same code under Java 7 I see a different behaviour in as much as when I close the last frame I opened, the next one to become active is the first one.

To illustrate this another way, lets say I open 5 internal frames, 1,2,3,4 & 5

In java 6 when I close frame 5, frame 4 becomes the active frame.

In java 7 when I close frame 5, frame 1 becomes the active frame.

View Replies View Related

Swing/AWT/SWT :: How To Generate PDF File Of The Contents In AWT Frame

Sep 25, 2014

I have been doing a project of ERP solution using JAVA AWT FRAMES and MYSQL(for database purpose). Here there is an ADMIN portion, who has the authority to make PAYROLLS of individual employees. There is a Frame where individual employee details will be shown(like basic salary, HRA, no.of leaves, other allowances...etc) in text boxes.

Now what i want is to make a PDF file of that payroll, so that I can make a hardcopy of it. The idea is just like anyother online form fill-up, where at the end you submit and save (or export) as a PDF (or text file) document. But I mention that it is a stanalone project, not an online one (i think it doesn't matter though).

So the basic idea is how to make a PDF file by extracting the text field or choice contents from a frame in JAVA AWT.

View Replies View Related

Java Swing Frame Can't Call On Other Methods From Main

Mar 25, 2015

I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:

import javax.swing.*;
import java.awt.*;
 public class BelishaBeacon {
  public void BeaconFrame() {
JFrame frame = new JFrame();
JPanel panel1 = new JPanel();

[code]....

View Replies View Related

Swing/AWT/SWT :: Unable To Add Jpanel Dynamically Inside Single Frame

Oct 4, 2014

I am building a GUI application which consists of two panels "panel" and "panel1". "panel1" have a button "addTimer" when clicked it should add the "panel" to the frame if i gain click the button it should again add the "panel" without overlapping the previous "panel" rather it should be created below the previous "panel". If i click on the button "addTimer" n times it should add the panel n times. Along with this the frame size has to dynamically change depending on the number of panels produced. Below is the code i tried my level best to satisfy the above conditions.

package superTimerV2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SuperTimer extends JFrame {
private static final long serialVersionUID = 1L;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Detecting Mouse Click Inside A Box Painted In Frame?

Feb 9, 2015

In the method mouseClicked(MouseEvent me) the co-ords of the click are obtained.

* if they are within the confines of the rectangle rect, console output System.out.println("inside box") is displayed
* in either case the click co-ords are displayed in the console

I'm getting the co-ords of the mouse clicks but no message when the click is inside the box

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/*
Experiment 04 was successful. So now (Experiment 05) I must try and see if I can identify mouse clicks that occur within the rectangle.
*/

public class AFrame extends Frame implements MouseListener {
ARectangle rect;
public AFrame(ARectangle rect) {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Fitting Dynamic JTable Inside A Dialog Or Frame?

Apr 22, 2014

I want to calculate the height of a dialog that contain only a table depending on how many rows that table it has so I'm using the cross multiplication rule.For example i check initially that my table is well fitting into the dialog(Without space at the bottom) for some value and after that i use the cross multiplication rule because data are dynamic.But unfortunately this rule does not solve the problem.What's the best rule for fitting a dynamic table inside a dialog or a frame? Here is my code.

public class FlowLayoutChangingGap {
public static void main(String[] args) {
// just for testing perpose but data are getting from database and it's dynamic
Object[][] data = {
{ "Kathy", "Smith", "Snowboarding", new Integer(5) },
{ "John", "Doe", "Rowing", new Integer(3) },

[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 :: Hangman Game - No Graphics Show Up On Eighth Guess (Blank Frame)

Feb 5, 2015

I'm having some problems with the graphics of my hangman game. The graphic that's supposed to show up on the first guess (the hangman pole) doesn't show up until guess number 2. And on the eighth guess, no graphics show up (I just get a blank frame).

import java.awt.*;
import javax.swing.*;
public class HangmanFigure extends JPanel {
private int guesses;
private Image background;
public HangmanFigure() {
super();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Runtime Localization Of Swing Application

Mar 19, 2014

I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.If there a simple way of achieving this without having to create an event model for all GUI pages?

View Replies View Related

How To Make Panels Visibility Go False / True With Actionlistener

Jan 28, 2014

I'm trying to create a program that has two labels... one in the top left and one in the top right... so far when i run it only the one in the top right (label2) shows... also In the program there will be multiple button and when I click a button it will show a different panel and then i can go back to the first panel to select other panels... so far i haven't figured out how to make panels visibility go false/true with actionlistener. last thing... when i have more then one panel added to the frame none of them show up.

Java Code:

//Matthew
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test{
public static void main(String[] args){

[code]...

View Replies View Related

Best Way To Run A Swing Application On The Web?

Sep 13, 2014

What is the best way to run a Swing application on the web? Should I convert it to an applet or do something else?

View Replies View Related

Execution Of Swing Application On Another PC

Apr 6, 2014

I am writing a Java Swing GUI application on my pc. I have to give this application to my cousin with another pc, where he is not aware of programming. then how can he execute that application? are there any ways of skipping the "javac" and "java" procedures while executing the app on his computer?

I am using win7 x86 and same at my cousin's place. I am also using eclipse-kepler sr1 ide for app development.

Are there any easy ways of automating this "javac" and "java" process(compilation and execution)? something like...scripting?

View Replies View Related

Swing/AWT/SWT :: Application Just Stop Itself During Execution

May 18, 2014

I made a check4 application with Java.It correctly works but sometimes the application just stop itself during the execution.I never had a problem like this. The application just stop itself and i can't even quit using the closing button..

View Replies View Related







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