jframe

Can't repaint my JFrame/JPanel

痴心易碎 提交于 2019-11-29 17:29:10
I have created a program that just moves a ball across a screen. I used to have it all in one class, but decided that it looked too messy so I split it up into three different classes: Main... initializes everything, Game... which paints everything and is a JPanel, and AL which is a KeyListener (which is also where the problem is). The problem is that I can't get the program to repaint from my AL class no matter what I try to pass into it. Can anyone help with this? Here are my three classes: import java.awt.Color; import javax.swing.JFrame; public class Main { static Game game; static JFrame

Add values when JCheckBox clicked

╄→尐↘猪︶ㄣ 提交于 2019-11-29 17:13:54
My program contains a label with the caption “Choose a coffee” and four check boxes – Americano, Espresso, Double Espresso and Latte. Note: A JCheckBox array is recommended here) I need to add event handling code to allow the user to purchase one or more items. The bill amount is displayed in a label after the user has made their selections. The prices are Americano €3.75, Espresso €4.00, Double Espresso €4.50 and Latte €3.50. An array is suitable here also. As the user makes a choice a label is displayed showing the bill. I cant figure out how to add the cost when the check box is selected

Changing and Updating JPanel Components externally, from JFrame is not Working, Swing

杀马特。学长 韩版系。学妹 提交于 2019-11-29 17:13:20
I was working with JPanel (Changing its component), but I want to change it from External JFrame. Sorry, I make this code with Netbeans (I know it put some stuff not needed for this question) and try to clean editing it, because the real code it is more large Here the code of the JPanel, with name 'MyPanel'. public class MyPanel extends javax.swing.JPanel { private javax.swing.JButton filling = new javax.swing.JButton(); private javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane(); private javax.swing.JTable myTable = new javax.swing.JTable(); private final javax.swing.table

Setting a background image on a JFrame using Swing

无人久伴 提交于 2019-11-29 16:52:46
I have been learning Java for a few weeks now and I am really stuck when it comes to applying a background image to a JFrame. Every tutorial I've come across doesn't create Frames the way I do ( I extend JFrame ) or if they do, the instructions aren't clear enough for me to understand. The code below is from a project of my own so help me practice what I've learned so far. Please could you build on the code below and explain to me what to add and where, so I may have an image as the background to my frame? One thing I would really appreciate is if you could explain how things work and why

Disposing JFrame by clicking from an inner JPanel

♀尐吖头ヾ 提交于 2019-11-29 16:25:45
I'm trying to dispose my JFrame by clicking a button, located on a JPanel that is placed on the JFrame that I want to close. I tried to make a static method on the JFrame class, but ofcourse my IDE told me that wasn't going to happen. Anyone thinking of a solution? Thanks! Try this: public class DisposeJFrame extends JFrame{ JPanel panel = new JPanel(); JButton button = new JButton("Dispose JFrame"); public DisposeJFrame(){ super(); setTitle("Hi"); panel.add(button); add(panel); pack(); button.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) {

What is the proper way to swap out an existing JPanel in a JFrame with another?

落爺英雄遲暮 提交于 2019-11-29 16:25:21
I'm building a program that requires swapping out the current, visible JPanel with another. Unfortunately there seems to be multiple to go about this and all of my attempts have ended in failure. I can successfully get the first JPanel to appear in my JFrame, but swapping JPanels results in a blank JFrame. My Main JFrame: public class ShellFrame { static CardLayout cl = new CardLayout(); //handles panel switching static JFrame frame; //init swing on EDT static MainMenu mm; static Panel2 p2; static Panel3 p3; public static void main(String[] args) { initFrame(); } public static void initFrame()

Dynamically resize jframe/image or scroll

不羁岁月 提交于 2019-11-29 16:10:48
As discussed in this question ( Wrap image to Jframe ), i need a jframe to match the exact provided image (The image itself is originally a PDF which has been converted to an image) The solution provided does indeed build a jframe to my image dimensions, but i can't actually see all of the image. I need to be able to resize the jframe, with the image dynamically adjusting to the new jframe size. Failing that, i think if i could just scroll the jframe or even zoom in or out, i could at least get to the parts of the image that i currently cannot see. The reason i need this is that, within my

Change Jframe Shape

a 夏天 提交于 2019-11-29 16:07:13
In c# you could change the form shape to be as some picture shape that you draw.. I wonder if there is the same option to do this on jFrame in java? (I'm using netbeans) and for example this is the picture I want to be used as the jFrame shape so inside the "phone screen" I want to add some buttons.. is it possible? Android Look and Feel Everything on an Android screen is a rectangle. Widgets are rectangles. Launcher icons are 96 x 96 pixel squares. The text under a launcher icon makes them a rectangle. The screen resolution of a Samsung Galaxy S3 is 1,280 x 720 pixels. The screen resolution

How do you make key bindings for a java.awt.Frame?

喜你入骨 提交于 2019-11-29 15:30:26
Background My window is a java.awt.Frame, and inside of the Frame are two Panels (java.awt.Panel). I'm trying to make it so that the window handles buttons I press. Try Number 1 I tried using a KeyListener, making the Frame implement the KeyListener. I added the KeyListener to the Frame, but the KeyListener functions didn't do anything when I pressed keys. (I tried printing with System.out.println().) Try Number 2 I tried following this tutorial: http://tips4java.wordpress.com/2008/10/10/key-bindings/ . Here is the my attempt to handle pressing the SPACEBAR: public void registerActions(){ //01

Java: How can I bring a JFrame to the front?

假如想象 提交于 2019-11-29 15:27:21
I am currently waiting for a very important announcement and I have created a simple application to check every 30 minutes whether the announcement was made or not When the announcement is made, I want a window to pop up and inform me about it. The window is just a simple JFrame that has some text in it. I have a class called Announcement. Inside this class I define another class for the frame called Form, so I have something like this: class Form{ public Form(){ //create frame and show it JFrame frame = new JFrame("anouncement"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container