jframe

Swing , Multiple Screens , Transfer of control

佐手、 提交于 2019-11-26 17:49:28
问题 I am developing a swing application. I am using two screens 1.A button from screen1 will launch screen 2. PseudoCode : ScreenA extends JFrame{ onButtonClick(){ Screen2.setVisible(true); } System.out.println("Hai"); } Screen2 extends JFrame{ onButtonClick{ Hide this screen; } } Now the output is : The screen 2 will be displayed 2.Hai will be printed. My Objective : I want to display hai only when a button from screen 2 is clicked and screen 2 dissppears. How do i achieve it ? I tried setting a

BufferStrategy vs DIY Double Buffering in JFrame

∥☆過路亽.° 提交于 2019-11-26 17:25:58
问题 Until now, I've done double buffering by creating and Image, drawing what I wanted to that Image using its associated Graphics object then draw that Image to the screen using the paint method's Graphics object. Recently, I learned about the BufferStrategy class and its uses. I was wondering what are the pros and cons of the two methods. EDIT: I dont't think I made my question very clear. I wanted to know the pros/cons of both the DIY method and the BufferStrategy and when, if ever, I should

Why do we need to extend JFrame in a swing application?

纵饮孤独 提交于 2019-11-26 17:25:50
问题 Why do we need to extend the JFrame class when building a Swing application. As far as I know extends is used for inheriting the base class. None of the functions of the JFrame class are used in the following program but still it is extended. I know I am missing out on some information. Is it like some of the functions of JFrame class are running in the background. 1) Code import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event

How to switch JPanels in a JFrame from within the panel?

半世苍凉 提交于 2019-11-26 17:24:58
问题 So, I'm trying to make a basic functional menu for a simple game. I tried to do this by creating 2 JPanels, one for the actual game, and another for my menu. What I'm trying to do is have a button on my Menu panel that when pressed, switches the JPanel being displayed in the parent JFrame from that of the menu to that of the actual game. Here is my code: class Menu extends JPanel { public Menu() { JButton startButton = new JButton("Start!"); startButton.addActionListener(new Listener()); add

How to add JCheckBox in JTable?

雨燕双飞 提交于 2019-11-26 17:05:46
问题 First of all i apologize for my english neglect that i will explain all my problem. First i want JCheckBox in the JTable i have. I am retrieving student id and student name from database in column index 0 and 1. I want third column should be Absent/Present which will initially take whether student is present or absent by JCheckbox Value. Here my code for JTable values : Attendance.java /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package

How to focus a JFrame?

限于喜欢 提交于 2019-11-26 17:01:05
问题 I am writing a small game, with one JFrame that holds the main game, and another JFrame that displays the score. the problem is, when I am done constructing them, the score JFrame always ends up focused! I have tried calling scoreDisplay.toFront(), scoreDisplay.requestFocus(), and even: display.setState(JFrame.ICONIZED); display.setState(JFrame.NORMAL); Is there any way to make this work? Thanks in advance, john murano 回答1: Have you consider setting the score in the same frame as the game

How to fit Image size to JFrame Size?

断了今生、忘了曾经 提交于 2019-11-26 16:54:34
问题 I have a JPanel into a JFrame . I loaded a picture on the JPanel but its shown just a part of the picture: This is the part of the code where i did it: JPanel panelImg = new JPanel() { public void paintComponent(Graphics g) { Image img = new ImageIcon("Welcome.png").getImage(); Dimension size = new Dimension(img.getWidth(null), img.getHeight(null)); setPreferredSize(size); setMinimumSize(size); setMaximumSize(size); setSize(size); setLayout(null); g.drawImage(img, 0, 0, null); } }; mainFrame

Changing the JFrame title

谁都会走 提交于 2019-11-26 16:53:52
问题 This code compiles, I just can't get the name to change on the title bar. import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class VolumeCalculator extends JFrame implements ActionListener { private JTabbedPane jtabbedPane; private

JFrame: get size without borders?

谁说胖子不能爱 提交于 2019-11-26 16:49:15
问题 In Java, is it possible to get the Width and Height of the JFrame without the title and other borders? frame.getWidth() and frame.getHeight()1 seems to return the width including the border. Thanks. 回答1: frame.getContentPane().getSize(); 回答2: frame.pack(); System.out.println("frame width : "+getWidth()); System.out.println("frame height: "+getHeight()); System.out.println("content pane width : "+getContentPane().getWidth()); System.out.println("content pane height: "+getContentPane()

Java Swing: How can I implement a login screen before showing a JFrame?

痴心易碎 提交于 2019-11-26 16:42:11
I'm trying to make a little game that will first show the player a simple login screen where they can enter their name (I will need it later to store their game state info), let them pick a difficulty level etc, and will only show the main game screen once the player has clicked the play button. I'd also like to allow the player to navigate to a (hopefully for them rather large) trophy collection, likewise in what will appear to them to be a new screen. So far I have a main game window with a grid layout and a game in it that works (Yay for me!). Now I want to add the above functionality. How