jframe

Is there a way to update the display window when the user loads a new image?

喜夏-厌秋 提交于 2019-12-11 18:19:21
问题 I am writing a program that loads an image(stack of images in one file) and do some operations on the image with the controls (buttons) and being able to load another image on the frame without having to change previous controls. The frame has a default window image at the start of the program. There is a button that loads a new image from the wanted directory. However the image never gets updated when the loadImage button is pressed. How do I get my frame to update the image window when a

Java method that runs when window is opened

别等时光非礼了梦想. 提交于 2019-12-11 18:10:02
问题 I need to set up a listener that can call a method every time a show() method is invoked to display a window. How can I do this? 回答1: You'd probably be interested in WindowListener . From the tutorial, "How to Write Window Listeners": The following window activities or states can precede a window event: Opening a window — Showing a window for the first time. Closing a window — Removing the window from the screen. Iconifying a window — Reducing the window to an icon on the desktop.

java.lang.IllegalArgumentException: adding container's parent to itself

守給你的承諾、 提交于 2019-12-11 17:56:26
问题 I have following code: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GUI extends JFrame { private JLabel text, result; private JTextField volt, amper, ohm, capacity, time, tensionChange, stream; private JButton calculate, next, previous; private JPanel header, panel1, panel2, panel3, panel4, panel5, panel6, panel7, panel8, panel9, card, pane; private CardLayout cards; private double voltNumber = 0; private double amperNumber = 0; private double ohmNumber = 0;

How to get result on second window multiple times instead of another open?

99封情书 提交于 2019-12-11 17:32:33
问题 I want to make a simple addition program. In it I want to pass variables from Main_Window to Second_Window for addition and I want to get result on Second_Window multiple times. Means If I pass variables multiple times from Main_Window for addition then result should be on Second_Window not third and fourth Window . Here I want All changes should be show on Second_Window not another on open. These lines are written for passing variables from Main_Window . Second_Window s = new Second_Window(a

How to add a new JFrame with buttons?

穿精又带淫゛_ 提交于 2019-12-11 16:32:53
问题 Whenever I create a new JFrame screen the game won't run on my computer for some reason and I don't know why. I have tried fixing this issue but I think it has something to do with the buttons or the placement of the screen. The startStage is what I need help on. If I'm missing something can you please tell me. import java.awt.CardLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event

How to handle termination and suspension of multiple Java Threads in JFrame?

假如想象 提交于 2019-12-11 15:43:33
问题 I have a Java GUI application based on JFrame, which uses a Java Class that controls multiple Java Threads: I'm trying to control any thread from Control Class to Terminate a thread Suspend a thread Un-suspend a thread So far, Control Class can create a thread and add it to ArrayList to keep track of all created threads: public class Control { ArrayList<myThread> threads; int counter; Control() { // do construction work.. } int createThreadAndRun(String keyword) { // create an instance of

How to create obstacle in swing

青春壹個敷衍的年華 提交于 2019-12-11 15:29:58
问题 I want to create this obstacle in red color in Java class Grid extends JFrame{ public Grid(){ setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(250,300); // Set the width,height,number of rows and columns final GridPanel panel = new GridPanel(300, 300, 10, 10); add(panel); } } class GridPanel22 extends JPanel{ int width, height, rows, columns; int gridWidth, gridHeight; public GridPanel22(int width, int height, int rows, int columns){ gridHeight = height / rows; gridWidth

Inclined plane Java (Triangle with angle)

落花浮王杯 提交于 2019-12-11 14:57:11
问题 i need to create an inclined plane according to a certain angle with a bloc on it and then use the physics laws to see if the bloc slides or not. For now, i created my bloc with a Path2D.Double, but i can't find a way to change the angle of the bloc. The angle is chosen from a spinner in the frame in the application.I created 2 class, one is the Frame, and the other is the Panel, where i draw my bloc. Here is the code of my path: @Override public void paintComponent(Graphics g) { super

How to get the parent container of a JWindow in Swing?

守給你的承諾、 提交于 2019-12-11 14:37:52
问题 I have one JFrame and calling a JDialog from that frame while initializing. In the dialog have a JButton , when clicking on the button a new JWindow opens. Can I fix the position of window in the main frame? How to access the parent container ( JFrame extended) from JWindow extended class? 回答1: Use SwingUtilities.getWindowAncestor, if inside the JWindow class, refer it as this , if no, simply put object inside: JFrame topFrame = (JFrame) SwingUtilities.getWindowAncestor(this); JFrame topFrame

JButton not appearing on JFrame

若如初见. 提交于 2019-12-11 14:12:23
问题 Following is the code in which the jbutton is not showing on the frame. I have also set visible to true. Even then the button doesn't appear. class gui{ public static void main(String args[]){ layoutBorder lb=new layoutBorder("check"); } } class layoutBorder extends JFrame{ layoutBorder(String title){ super(title); setLayout(null); setSize(200, 200); JButton jb=new JButton("JB"); add(jb); setVisible(true); } } 回答1: If you want null layouts then you need to set sizes and position by yourself.