jframe

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

醉酒当歌 提交于 2019-12-01 11:05:49
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 indication of errors of any kind. Does anyone know why this happens? Warbler calls System.exit() after your main

Java hangman game with gui, problems with incrementing/decrementing numbers

会有一股神秘感。 提交于 2019-12-01 11:04:42
问题 The following part of the code doesn't work, as the won/lost count keeps incrementing by more than 1 for each word, and sometimes I get a nullpointerexception with the string length. Moreover, although the player is supposed to get 7 tries(int no), sometimes he gets more, sometimes less. The Strings are taken from a text file "Hangeng.txt". The whole game is inside a keyboard keytyped listener that is inside a button listener. Any tips on how the layout of the game should generally be

How to animate Rectangle in JPanel?

寵の児 提交于 2019-12-01 10:36:28
问题 I want to learn some tricks about JAVA for my project. I want to animate my Rectangle leftoright and righttoleft but I can't apply the same functions for ball animation. In addition,how can I start my ball in different x-direction with a border of y-coordinate ? Thanks a lot for your advices and helping. My codes: import javax.swing.Timer; import java.util.ArrayList; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MultipleBall extends JApplet { public

How do you use re-size all Graphic2D

十年热恋 提交于 2019-12-01 10:32:47
In java how can you make a game fully realizable! But so logic and graphics can work with it? I have tried using SCALE methods. But this doesn't allow perfect full-screen for every computer. So I made this: public void resize(int WIDTH, int HEIGHT, boolean UNDECORATED) { frame.setPreferredSize(new Dimension(WIDTH, HEIGHT)); frame.setMaximumSize(new Dimension(WIDTH, HEIGHT)); frame.setMinimumSize(new Dimension(WIDTH, HEIGHT)); this.WIDTH = WIDTH; this.HEIGHT = HEIGHT; frame.setUndecorated(UNDECORATED); frame.setSize(WIDTH, HEIGHT); } So you can set your screen size to whatever you want! It

Displaying JTable in JFrame

为君一笑 提交于 2019-12-01 10:26:52
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, it works. Here is my stack trace I am getting: java.lang.ArrayIndexOutOfBoundsException: 0 >= 0 at java

How to remove the title bar from a JFrame screenshot?

懵懂的女人 提交于 2019-12-01 09:36:12
I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below: public BufferedImage getScreenshot() { java.awt.Dimension dim = this.getPreferredSize(); BufferedImage image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); this.paint(image.getGraphics()); return image; } where this extends JFrame. The image that I get has a blank strip along the top where the title bar was. What's the most straightforward way to capture an image of the contents of the JFrame without the extra space allocated for the title bar? You should be able to use the

How to set Jframe Background Image in GroupLayout Java

梦想的初衷 提交于 2019-12-01 09:22:40
Am trying to set a background image for my frame but it does not work. I tried this link: Setting background images in JFrame The code: setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("/Images/about.png"))))); I tried adding the above code to my Contentpane but it does not work. public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { MainMenu frame = new MainMenu(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public MainMenu() { setIconImage(Toolkit.getDefaultToolkit()

Will new instance of JVM or reflection help in this case

偶尔善良 提交于 2019-12-01 08:43:20
I had a problem that I posted before but got no clear solution How to prevent JFrame from closing . So I am posting a SSCCE may be this might help in better understanding the problem being faced package myApp; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import javax.swing.JFrame; import App2.Applic2; public class MYApp { @SuppressWarnings({ "unchecked", "rawtypes" }) public static void main(String arg[]){ JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle("Application frame 1"); f.setSize(200,200); f.setVisible(true);

How to remove the title bar from a JFrame screenshot?

跟風遠走 提交于 2019-12-01 08:12:49
问题 I'm capturing a screenshot image of a JFrame via a "double buffering" approach, per below: public BufferedImage getScreenshot() { java.awt.Dimension dim = this.getPreferredSize(); BufferedImage image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); this.paint(image.getGraphics()); return image; } where this extends JFrame. The image that I get has a blank strip along the top where the title bar was. What's the most straightforward way to capture an image of the contents

Optimal location for a modal JDialog to avoid stuck

人走茶凉 提交于 2019-12-01 08:03:17
My Swing application has to show a modal dialog to the user. Sorry for not posting SSCCE. topContainer might be JFrame or JApplet . private class NewGameDialog extends JDialog { public NewGameDialog () { super(SwingUtilities.windowForComponent(topContainer), "NEW GAME", ModalityType.APPLICATION_MODAL); //add components here getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); //TODO: setSize(new Dimension(250, 200)); setLocation(650, 300); } } I start the dialog like this on network event SwingUtilities.invokeLater(new Runnable() { @Override public void run() {