jframe

Why JMenuBar is not place in the JFrame content pane, but JToolbar place in the content pane

↘锁芯ラ 提交于 2019-11-28 14:43:39
Why JMenuBar is not place in the content pane?is there any reason or effects when make a java gui program especially when using jframe? Thanks As stated in Using Top-Level Containers article, the manu bar is managed by the Root Pane: Each top-level container relies on a reclusive intermediate container called the root pane. The root pane manages the content pane and the menu bar, along with a couple of other containers. You generally don't need to know about root panes to use Swing components. However, if you ever need to intercept mouse clicks or paint over multiple components, you should get

Java Swing — Key Input with JPanel added to JOptionpane

廉价感情. 提交于 2019-11-28 14:43:31
When I run the code, the added Example1 class to the JOptionPane (in Frame) should get keyInput and then change the y value of the player instance (in example1), but it doesn't work. Also, how would I be able to rotate the ship on its axis and then move in the direction its facing? Currently it moves in the direction its rotated towards, but it rotates on what seems the coordinates 0,0. Frame import javax.swing.*; import java.awt.*; /** * Created by griffin on 12/7/2015. */ public class Frame extends JFrame { public Frame() { initUI(); } private void initUI() { JTabbedPane jtp = new

Java frame not displaying properly during a while loop

╄→гoц情女王★ 提交于 2019-11-28 14:36:45
Here's a serious issue im having with a jFrame. I have one "Main Frame" where everything is done from, however i have another frame with a gif image in it (Loading, that circle that goes round and round), that is used as a splash screen saying "Processing, Please wait", however when i pull through that frame and my while loop runs, the frame goes blank and nothing displays until after the loop. I am assuming that this is due to the while loop consuming computer resources and "blocking" any other process from running. Please advise on what i should do. the code for declaring the new frame is

How do I use CardLayout for my Java Program for Login and Menu Items

十年热恋 提交于 2019-11-28 14:20:12
I am creating a "Store" program that basically can allow an employee to log in with a username and password I provide. After logging in, the employee can then see a "main menu" with four buttons: Sales Register, PLU Settings, Settings, and Logout. From this screen, the employee can proceed by clicking on any of the buttons to navigate to that screen. I do not want a new window to popup every time a button is clicked, but instead I want there to be some transition (or no transition) to go to the page that is clicked. So to give an example: When the employee starts the program, he/she is greeted

My JFrame always becomes a few pixels too big.

自闭症网瘾萝莉.ら 提交于 2019-11-28 14:05:36
I am working on this game in Java, and I just rewrote all my window related code from being based on java.awt to javax.swing. Soon after, I realized that things were a bit more complicated now, and so i did some research and and found out how to draw things, how to set the size of a JFrame, etc. But for some reason, the size of my JFrame always goes 10 pixels beyond the size I've specified it to become. In this case, I wanted it to be 640 by 640 pixels. Here's my code: package chrononaut; import java.awt.*; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*;

Specifying the location of Canvas in Swing

只愿长相守 提交于 2019-11-28 13:46:30
I'm learning Swing GUI design. One thing I haven't quite sorted out is how to add an add a Canvas to a specific location in a container. More specifically: I create a Canvas class that uses Paint method. Object of this class is added to a Panel. What I do not quite understand, is how and where it is added to a Panel. In Tkinter Canvas is a widget that contains only an image, but in Swing there is no similar widget (probably not the best word) added to the Frame that contains only Canvas object and nothing else. Sorry if it is too vague, I'm adding a self-contained code. Please ignore text

Nothing in my JFrame appears

久未见 提交于 2019-11-28 13:33:11
问题 I am practicing using GUIs. I have been following a set of instructions however when I try to run the program only an empty frame appears. No information can be seen inside the frame. here is the code I have: package practice528; import java.util.Scanner; import java.io.*; import javax.swing.*; import java.awt.*; public class Practice528 { public static void main(String[] args) { JFrame frame = new JFrame("Rectangle Calculator"); frame.setVisible(true); frame.setSize(400,300); frame

Thread.sleep() stopping my paint?

痴心易碎 提交于 2019-11-28 13:11:53
I'm making a program that is trying to animate a card moving across the screen as if you actually drew it from a desk. Here is the code for the animating: public void move(int x, int y) { int curX = this.x; //the entire class extends rectangle int curY = this.y; // animate the movement to place for (int i = curX; i > x; i--) { this.x = i; } this.x = x; this.y = y; } this rectangle object is inside of a panel inside of a jframe. for repainting the panel, i have this: public void run() { while (Core.isRunning()) { gamePanel.repaint(); //panel in which my rectangle object is in try { Thread.sleep

Java gui background image

对着背影说爱祢 提交于 2019-11-28 13:04:06
问题 I realise this question has been asked many times but I feel it has not been properly answered. I want to use an image as a background in a java gui I have tried the following: import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; public class worldGUI extends JFrame implements ActionListener { private ImageIcon world = new ImageIcon("C://Users/Hans/Documents/world/map.png"); private

Java Dialog Box [closed]

夙愿已清 提交于 2019-11-28 13:03:20
问题 How would I produce the following window: http://postimage.org/image/61aa8hrvb/ What would I use for formatting? Something similar to BorderLayout? Is there a better way? I have tried using a combo of JFrame, JPanel and JTextArea; as follows: public static void doListAllChecks() { int transCount = CAObject.getTransCount(); JFrame frame = new JFrame(); frame.setVisible(true); JPanel content = new JPanel(); for (int idx = 0; idx < transCount; idx++) { Transaction tObj = CAObject.getTrans(idx);