jframe

Java can only display 1 image on JFrame

心不动则不痛 提交于 2020-03-05 11:46:41
问题 I am trying to display two different images on my screen. one of which is a banner that goes at the top of my JFrame , and another that I just placed randomly below the banner for testing purposes. The issue I am having is that while I can display a single image on the screen by adding an object of class WindowStructure to my window, I am not able to display more than one image at a time. Only the last image added to the window is displayed on the screen: Here is the window class: import

Java: How can I modify the size of a JPanel in runtime?

别来无恙 提交于 2020-03-05 09:29:12
问题 I want to modify the size of the JPanel while the program is running, for example with a menu item. How can I reach it? Or how should I modify my program to get acces to the live JPanel in the content pane? Edit: If I make a contentpane for a gamefield that's 400x400 in the start as default. But what if I want to ad an option in the menu to change the size to 500x500, but without losing all of the content already in progress by the player. JFrame class: package me.test; import javax.swing

How to setting setBorder for window application?

北慕城南 提交于 2020-03-03 10:07:25
问题 I tried create some application for monitoring network. I'm going to create 4 JPanels and insert, for example, panels insert_panel_0 , insert_panel_2 to panel_2 .I can't setting my borders between insert_panel_0 , insert_panel_2 . I have vertical gaps, but i don't have horizontal gaps. Could you help me solve it? import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing

Java小项目之:文件的加密与解密!再也不怕存的小电影被别人发现了!

。_饼干妹妹 提交于 2020-02-26 20:16:37
Java小项目之:文件的加密与解密!再也不怕存的小电影被别人发现了! 今天带来的java小项目是加密解密系统,再也不怕别人偷看自己的电脑了,也可以正大光明的存小电影了。减少借别人电脑被看隐私的尴尬,从这个项目开始! 界面展示: 部分代码展示: package wt.diy.encryption.gui; import java.io.File; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import wt.diy.encryption.service.ServiceContext; public class Context { ServiceContext service; EncryptionFrame frame; public Context(ServiceContext service) { this.service = service; } public void setFrame(EncryptionFrame frame) { this.frame = frame; } public void excute(String source,String destiny, String key,JFrame frame) { File

只需亿小串代码,教你用java仿制qq

六眼飞鱼酱① 提交于 2020-02-26 08:33:21
只需亿小串代码,教你用 java仿制qq 直奔主题,代码如下: import java.awt.Color; import java.awt.Container; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPasswordField; import javax.swing.JTextField; public class GUIQQ extends JFrame { // 用户名 private JTextField username; // 密码 private JPasswordField password; // 小容器 private JLabel jl1; private JLabel

Draw Shapes That User Selects

自作多情 提交于 2020-02-16 06:28:39
问题 I need to create a program to draw shapes(user chooses with radio button), and whether or not the shape is filled(user chooses with check box). This is the code I have so far: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SelectShape extends JFrame implements ItemListener{ private JRadioButton line = new JRadioButton("Line"); private JRadioButton rect = new JRadioButton("Rectangle"); private JRadioButton oval = new JRadioButton("Oval"); private JCheckBox fill

Draw Shapes That User Selects

主宰稳场 提交于 2020-02-16 06:28:19
问题 I need to create a program to draw shapes(user chooses with radio button), and whether or not the shape is filled(user chooses with check box). This is the code I have so far: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class SelectShape extends JFrame implements ItemListener{ private JRadioButton line = new JRadioButton("Line"); private JRadioButton rect = new JRadioButton("Rectangle"); private JRadioButton oval = new JRadioButton("Oval"); private JCheckBox fill

Updating a JLabel within a JFrame

爱⌒轻易说出口 提交于 2020-02-15 06:52:19
问题 I've been searching around this site and the internet for hours trying to figure out how to fix this problem. I'm creating a game and it's my first time using graphics. I figured out how to create a JFrame, JPanel and JLabel, and the only problem I can't seem to get around is updating the JLabel. Let's say I start it out like this: JLabel testing = new JLabel ("blah", JLabel.CENTER); testing.setAlignmentX(0); testing.setAlignmentY(0); frame.add(testing); I am able to change the text after a

Optimal location for a modal JDialog to avoid stuck

大城市里の小女人 提交于 2020-02-14 17:10:10
问题 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

Optimal location for a modal JDialog to avoid stuck

白昼怎懂夜的黑 提交于 2020-02-14 17:09:13
问题 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