jframe

How do I make Java wait for a method to finish before continuing?

我的未来我决定 提交于 2019-12-31 03:19:07
问题 So my problem is that I need these methods to run one after another but I cannot work out how to make the methods wait before being run. Any help is appreciated. Thank you. Here is my code: public void startMoving() throws InterruptedException { moveEnemy("right",3); wait(); moveEnemy("down",3); wait(); moveEnemy("right",2); wait(); moveEnemy("up",1); wait(); moveEnemy("right",2); wait(); moveEnemy("up",2); wait(); moveEnemy("right",2); wait(); moveEnemy("down",4); wait(); moveEnemy("left",1)

Image not at proper place after rotating (graphics)

妖精的绣舞 提交于 2019-12-31 02:18:09
问题 I am trying to display two rotating wheels with diameter 512untis at different rates but i am not able to remove the previous drawn image graphics and set the rotated graphics at the correct position. For now i am doing a rotation with arbitrary angle. I tried affineTransform and got the rotations but it was weird like all pixels spread away. Im using a while loop with thread.sleep(). The following is the code : //The drawSmallCircle and drawBigCircle return two images. class MyFramePart2

How to add jlabel image hovering?

人走茶凉 提交于 2019-12-31 02:09:08
问题 How would I go upon adding JLabel hovering? Like when you move your mouse over top a JLabel a and new image will overlap it. I know how to make it work with buttons, but the same technique will not work for JLabel s. Will anyone guide me towards adding JLabel hovering? Please and thanks. package src; import java.awt.Dimension; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; /* * @Author - 0x29A * * */ public class Jframe { public static void main(final

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

谁说我不能喝 提交于 2019-12-30 13:35:16
问题 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

Java JApplet to JFrame

风流意气都作罢 提交于 2019-12-30 12:22:50
问题 I want to convert a JApplet to a JFrame. I have found this code on the internet that is a word search game. I want to use this code in a demonstration for a class. but I don't want it in an applet. The code that I was going to paste in here was to large by about 7,000 characters. I tried taking the JApplet and extending a JFrame and then putting all of the code for the initialization into a constructor (Zero Argument constructor). This cause about ten errors that I couldn't get fixed. I want

How to add components to JFrame once it's visible without having to resize it?

别来无恙 提交于 2019-12-30 12:10:10
问题 I have a program where I have a JFrame with a JButton in it. When the user clicks the JButton , all Components of the JFrame are removed, and a JPanel with red background is added to it. When I click the JButton , that red JPanel does not become visible unless I resize the JFrame (I am using Windows 7). Is there a way to achieve what I want without having to manually resize the JFrame ? Here is a part of the code I am using: public class Demo implements ActionListener{ public static void main

JRuby script with Rubeus and Swing exiting once packaged into jar using warble

独自空忆成欢 提交于 2019-12-30 11:02:00
问题 I am trying to package a simple JRuby script into a jar file. The script uses Rubeus::Swing and runs correctly when executed with the JRuby interpreter. require 'rubygems' require 'rubeus' class Example01 extend Rubeus::Swing def show JFrame.new("Rubeus Swing Example 01") do |frame| frame.visible = true end end end Example01.new.show Once I package the script into a JAR with warble , when I execute: java -jar jtest.jar ... the JFrame window shows up and instantly closes. There is no

Displaying JTable in JFrame

人盡茶涼 提交于 2019-12-30 10:34:38
问题 What i want to do: I want to list some records of a database. This list should be displayed in a JFrame popup. Description: I have 3 classes: Main.java (runs program) PeopleTableModel.java (holds data, extends AbstractTableModel) PeopleTable.java (holds logic, extends JTable) Why I am getting an ArrayIndexOutOfBoundsException when setting my JFrame to visible? Update: It seems like this error only shows up, when I use my own PeopleTable class. When I assign the table to just a normal JTable,

How to go back to a JFrames in Java

三世轮回 提交于 2019-12-30 06:59:29
问题 I have a button in a JFrame, if pressed, it takes us to another frame. I used this code: private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { SecondForm secondform = new SecondForm(); secondform.setVisible(true); setVisible(false); dispose(); } So the new frame opens and everything is ok. Then i placed another button -in the second frame- in order to go back to the previous frame. I used this code: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

How to hide the default minimize/maximize and close buttons on JFrame window in Java?

泄露秘密 提交于 2019-12-30 04:46:11
问题 I would like to know if it is possible to create a JFrame window which has no default maximize/minimize(-) and close(x) buttons! I have added custom buttons on each frame so that the user does not have to mess around with the default ones on the top right corner of the window! 回答1: You can use JWindow because is by default un_decorated, but you can setUndecorated() for JFrame/JDialog another ways are implements WindowListener setDefaultCloseOperations 回答2: Use JFrame