jframe

frame 2 inside frame 1

江枫思渺然 提交于 2019-12-01 14:42:42
I have 2 classes; Students and RegisterStudents, and hence 2 different main_panel(Class 1) and panel_1 (Class 2). What I am trying to do is, when a button on the Students Interface is pressed, the whole panel_1 should appear within main_panel. I have set both to same size already. is that possible? The code i got so far is: JButton btnNewButton = new JButton("Register Student"); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { Students main_panel = new Students(); RegisterStudent panel_1 = new RegisterStudent(); main_panel.add(panel_1); }

Java Making objects move while buttons held

限于喜欢 提交于 2019-12-01 14:42:34
How do I make a JPanel move while a button is held down and stop when the button is released. I have tried using thread.start() with a Runnable and ways like that. I always run in to errors. Can anyone help me though? There are a number of important considerations that you need to take into consideration. Buttons aren't designed to work this way. They are designed to trigger and action event when they are clicked (pressed and released), so you can't use the normal action API. Lucky for us, there are other ways to determine the state of buttons. This example uses a ChangeListener on the

how does a swing timer work?

喜你入骨 提交于 2019-12-01 14:26:11
问题 hello i am having trouble trying to understand swing timers. to help me could someone show me a simple flickering animation? i have looked arround on the internet but still dont fully understand how they work. it would be so helpful if someone could give me an example like this: say if i created a circle: g.setColor(colors.ORANGE); g.fillOval(160, 70, 50, 50); how could i then use a swing timer to change the color from orange to say Gray using a swing timer with a delay? thank you so much for

How do I set up a JFrame with a refresh rate?

扶醉桌前 提交于 2019-12-01 14:17:03
I have a 2d game which the entire structure is completely coded except the graphics. I am just updating the single component of a JFrame which is a Graphic containing 50 images. Each frame the images are in a different location hence the need for a refresh rate. To paint, I have overridden the paintComponent() method, so all I really need to do is repaint the component (which, again, is just a Graphic) every 40ms. How do you set up a JFrame with 25FPS? trashgod This AnimationTest uses javax.swing.Timer . A period of 40 ms would give a rate of 25 Hz. private final Timer timer = new Timer(40,

Implementing CardLayout within a JFrame and switching cards based on specific button presses

℡╲_俬逩灬. 提交于 2019-12-01 14:14:49
I've posted my code below. I have the simple task of creating a navigable GUI. I've spent the past few hours doing research on how to accomplish this, and this is the code that I've put together. Originally I wanted to perform the navigation without any layouts or anything. I need the home panel to display after the user clicks on the "login" button on the welcome panel. It displays the welcome card just fine, but when I get to the validateLogin method(which is activated when the login button is press, and upon successful login it should show the home panel within cards) it simply stays on the

Java - Screen turns black, when setting a JFrame to Fullscreen

给你一囗甜甜゛ 提交于 2019-12-01 14:09:57
I'm trying to draw something on a Canvas, add it to a JFrame and then set this JFrame to Fullscreen. My problem is: in fullscreenmode I only see a black screen. Before the screen turns black I shortly can see the pink background of the canvas. Drawing directly on a JFrame and then setting it to fullscreen works perfectly fine and I can see the testtext. I assume there is a problem with displaying the Canvas properly. Here is my code: public class FullscreenTest extends Canvas { private JFrame mainFrame; public FullscreenTest(){ this.mainFrame = new JFrame(); JPanel contentPane = (JPanel)

how to make a frame display 50 times for 1 second and disappear each time it's displayed

淺唱寂寞╮ 提交于 2019-12-01 14:07:38
I need my JFrame to display itself within the dimensions of my screen and it should display the frame with the message then disappear for 1 second then reappear 50 times here's my code so far: import javax.swing.*; import java.awt.*; import java.util.*; public class OurMain { public static void main(String[] args) { Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize(); int w = sSize.width; int h = sSize.height; Random rand = new Random(); int z = rand.nextInt(sSize.width); int c = rand.nextInt(sSize.height); int x = (int)((Math.random()* w) - z); int y = (int)((Math.random()* h) - 100

How to set the JFrame as a parent to the JDialog

杀马特。学长 韩版系。学妹 提交于 2019-12-01 14:06:00
问题 I am having trouble to set the frame as a owner to the dialog. Normally when I extend JDialog class for creating a dialog then I use super(frame) to specify the owner of the dialog such that both of them are not disjoint when you press alt+tab . But when I create a dialog using new like JDialog dialog = new JDialog() then I am unable to specify the frame as owner to the dialog. Following example demonstrates above two approaches. Top Click button opens a dialog which is without extending

Adding images on Java JFrame - Netbeans

℡╲_俬逩灬. 提交于 2019-12-01 13:58:11
I'm using NetBeans 7.1 to code in Java. I have already created a JFrame filled with some labels, textbox and buttons . How can I do to import some image (JPG,PNG,etc...) from my PC into the same JFrame ? On an specific location of the frame. Open the form in NetBeans form editor. Add a JLabel from the pallete to the form Select the label you just added and click the "..." button next to the icon property Fill out the properties. It's normally best that the images reside within the project folder, makes deployment easier in the long run. Copy Image to your Netbeans project. Add new label to the

replacing the dot character in the password field, Jframe, Java

拈花ヽ惹草 提交于 2019-12-01 13:21:39
I want to ask how can i change the character in the password field that was the point I want to replace with a star ??? i'm using Jframe, Java nukebauer PasswordTextField.setEchoChar('*'); 来源: https://stackoverflow.com/questions/13390247/replacing-the-dot-character-in-the-password-field-jframe-java