jframe

Integrating Swing in a simple text adventure game

一笑奈何 提交于 2019-12-04 06:54:23
问题 I am fairly new to some intermediate concepts in Java. Recently I made a text adventure game called DazzleQuest that runs entirely in the developer console/terminal. It involves my friends as characters so I wanted to show it to them and gain experience with Java by transferring the functionality of the command line and output from the console to a simple Swing interface comprised of a JTextArea to show the game's output and a JTextField , with ActionListener , to handle commands from the

Java - Custom shaped draggable JFrame

二次信任 提交于 2019-12-04 06:43:40
问题 so I made a custom shaped JFrame using setShape(s); and I got it to look how I wanted the problem when you set the JFrame to be undecorated you can't drag the Frame with your mouse on the screen, so I tried to implement my own draggable frame, but it's not working as supposed to, here's the Frame class : package rt; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Polygon; import java.awt.Shape; import java.awt.event.MouseEvent; import java.io.IOException;

setIconImage only works in eclipse, doesnt work when exported as runnable jar file

廉价感情. 提交于 2019-12-04 06:40:05
问题 I have searched for a while now for a fix to this. I have a project folder in my workspace (that folder is basically my root), and in it there is a file called icon.gif. In my program, I have the following: package com.mgflow58.Main; import javax.swing.ImageIcon; import javax.swing.JFrame; public class Game { public static void main(String[] args) { JFrame window = new JFrame("Guppy's Adventure"); window.add(new GamePanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window

java.lang.IllegalArgumentException: adding a window to a container

拟墨画扇 提交于 2019-12-04 06:31:45
问题 I get 'java.lang.IllegalArgumentException: adding a window to a container' when I call frame.add(this). What am I doing wrong, and how do I fix the error. Thanks in advance. public class mainclass extends JFrame{ private static final long serialVersionUID = 1L; private int width = 400; private int height = 400; public static JFrame frame; public static void main(String args[]) { frame = new JFrame(); mainclass mainclass = new mainclass(); mainclass.createFrame(); } public void createFrame() {

Simple KeyListener not working

冷暖自知 提交于 2019-12-04 06:22:35
问题 I'm working on a really simple project in Java to try to understand how to use KeyListener. I've created a Main class and a KeyListener, MouseListener class. I want to get something to happen when I press a keyboard key. So far the only thing that is working is "Hello" when I click. Here is my code: import javax.swing.JFrame; import javax.swing.JPanel; public class KeyPractice{ public static void main(String[] args) { JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel

jFrame GetGraphics is null in java While Drawing image

倖福魔咒の 提交于 2019-12-04 06:04:31
问题 I'm getting null exception error while drawing image to jframe. i debug the code and check the image and frame is not null but still it is throwing NULL exception while drawing image to frame. Please have a look : public void run(){ try{ ObjectInputStream objVideoIn = new ObjectInputStream(serVideoIn); byte[] imgbytes=null; ByteArrayInputStream barrin=null; JFrame jf = new JFrame(); Graphics ga=jf.getGraphics(); //Getting null exception //Thread.sleep(10000); jf.setVisible(true); jf.setSize

Set opacity of a decorated JFrame in Java 8

独自空忆成欢 提交于 2019-12-04 05:58:41
I would like to know how to get a transparent JFrame in the latest version of Java. Currently, you can only use <JFrame>.setOpacity(); if the frame is not decorated . I have no use for an undecorated frame, so I'd like to know how to go around this restriction and set the opacity of the frame to 0.5f while still keeping the title bar, resize options etc. I have read the docs here: http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html . The code only worked on Java 6 and no longer runs. The error, as I said, is: Exception in thread "AWT-EventQueue-0" java.awt

Components in second JFrame not showing up

久未见 提交于 2019-12-04 05:57:04
问题 i want to start another JFrame from pressing a button in a JFrame. But if I press the Button it shows the JFrame but not the Buttons and Sliders in it. public class MainMenu extends JFrame { private JFrame klick; private static final long serialVersionUID = 9002; public static void main(String[] args) { new MainMenu(); } public MainMenu() { buildGUI1(); } public void buildGUI1() throws NullPointerException { setTitle("Hauptmenü"); setSize(800, 480); setLayout(new GridLayout()); setAlwaysOnTop

Dispose a JFrame on button click from another JFrame

笑着哭i 提交于 2019-12-04 05:16:10
问题 As many probably know, I am a complete Java newbie. I have already attempted to research this (by reading other posts on StackOverflow, Googling and asking a friend who is less of a java newbie) but I can't figure it out. The answer is probably clear and easy but I am blind to it. I am attempting to dispose a JFrame from a different frame. My application is supposed to work as follows: Frame X has a button, when pressed: spawns frame Y Frame Y has a button, when pressed: spawns frame Z Frame

Set the same font for all component Java

依然范特西╮ 提交于 2019-12-04 05:15:05
I want to set a specific font for all component in a JPanel but I prefer that the question is still more general and not limited to the JPanel. How can I set the font to a list of component in a container (JFrame or JPanel)? Here is a simple method that allows you to specify Font to the whole components tree under any Container (or just a simple Component, doesn't matter): public static void changeFont ( Component component, Font font ) { component.setFont ( font ); if ( component instanceof Container ) { for ( Component child : ( ( Container ) component ).getComponents () ) { changeFont (