jpanel

Type mismatch error when adding JLabel/JPanel to Scala Swing Panel

落花浮王杯 提交于 2019-12-12 01:50:06
问题 I'm trying to incorporate a java native JLabel (or a JPanel) to a scala swing application and I'm stuck with the compile error. The code I'm trying to run is the following. package com.david import javax.swing.JPanel import scala.swing._ object Hello extends SimpleSwingApplication { def top = new MainFrame { title = "First Swing App" contents = new JPanel() } } The compiler gives me the following error. $ sbt compile [info] Set current project to MyGui (in build file:/home/david/programming

how can i draw a circle again if it goes too far on a JPanel

不打扰是莪最后的温柔 提交于 2019-12-12 01:47:45
问题 I am trying to make a program that starts with 7 circles at the top of a JPanel. All the circles have a random size and color. The circles start at the top of the screen and move downwards once they reach the bottom of the JPanel they should reappear at the top of the JPanel and move downwards again. I can already make the circles move downwards but I am unsure of how to draw them back at the top again. I made a method called replaceCircle to use to draw the circles back at the top of the

Java Swing GUI doesn't seem

眉间皱痕 提交于 2019-12-12 01:42:53
问题 I'm trying to make a GUI based on BorderLayout and GridLayout by hand-writing not with a form builder. Because of that, I'm most likely skipping a part in the code. It is loaded but not seem. import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.net.InetAddress; import javax.swing.*; import javax.swing.border.EmptyBorder; class PanelDemo { JButton jbtnUpArrowFirst; JButton jbtnDownArrowFirst; JButton jbtnUpArrowSec; JButton jbtnDownArrowSec; JButton

Loading an image into a background in java

北慕城南 提交于 2019-12-12 01:28:44
问题 How do you load an image into a background in Java? I have tried many different methods and none of them work so I am asking if anyone knows how to upload a png image into a jpannel 回答1: Make your own JPanel. Add an object of PicPanel in your GUI's constructor. class PicPanel extends JPanel{ private BufferedImage image; private int w,h; public PicPanel(String fname){ //Pass picture's filename as a parameter. //reads the image try { image = ImageIO.read(getClass().getResource("/"+fname)); w =

Two JPanels in one JFrame

不羁的心 提交于 2019-12-12 01:28:25
问题 I want to use two JPanels in one JFrame, with an invisible horizontal line between them. I played a little bit and got this: public class Application { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setSize(500,700); jframe.setVisible(true); jframe.setTitle("Title"); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setResizable(false); JSplitPane splitPane = new JSplitPane(); JPanel leftPanel = new JPanel(); JPanel rightPanel = new JPanel();

JPanel won't display

我与影子孤独终老i 提交于 2019-12-12 01:04:22
问题 I got a class that's supposed to launch a game (with main() ), and the game's opening screen. The class with main() (named Starter ), that extends JFrame , creates a new OpeningScreen class (extending JPanel), and adds it to the JFrame. For some reason, the OpeningScreen won't be added to the JFrame. Code: Starter class: import javax.swing.*; import java.awt.*; public class Starter extends JFrame { public Starter(){ setSize(500,500); setResizable(false); setTitle("Ping-Pong Battle");

Change a JPanel dynamically based on JRadioButton

别等时光非礼了梦想. 提交于 2019-12-12 00:54:34
问题 I'm trying to change content dynamically based on a JRadioButton selection... My simplified code looks something like this. //import public class Thing { // JPanel pnlMain, pnl1, pnl2, pnlRt, pnlLt; JRadioBtn btn1, btn2; // Thing () { // //initialize panels, add to them, etc. pnlMain.add(pnlLt); pnlMain.add(pnl1); pnlMain.add(pnlRt); // //Get it showing and stuff. // } // //One instance of this class connected to all radio buttons. class Evt implements ActionListener { public void

swing component not visible

此生再无相见时 提交于 2019-12-12 00:47:43
问题 I am working on an application and I am stuck in the incipient phase. I have a JTextField in a JPanel in a JFrame . JTextField isn't there. If I use JPanel p0 = (JPanel) f.getContentPane(); it works. But Not with JPanel p0 = new JPanel(); f.add(p0); So the problems are: Why is not the field visible? (most important q) What's the difference between the 2 aforementioned approaches? Code: import java.awt.*; import java.io.*; import java.net.*; import java.util.*; import javax.swing.*; public

How to delete an JPanel Object?

随声附和 提交于 2019-12-12 00:24:54
问题 Im on to create a little "game", something like an 2d AirForce Shooter. So, i have a problem with deleting unused enemys. An Enemy is an simple JPanel, which is saved in the main logic as an array List. public static ArrayList<Enemy> enemys = new ArrayList<Enemy>(); The Enemy run logic does the following: while(!destroyed){ if(Game.running){ x--; if(getBounds().intersects(Field.player.getBounding())){ Player.death = true; } if(x < 0){ Field.deleteEnemy(this); } setBounds((int) x, (int) y, 100

MS Word like page managment [closed]

一曲冷凌霜 提交于 2019-12-11 22:53:53
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . This is more of a logical problem/disscusion. I have a text editing program that works similar to MS Wrod. It's document is composed out of pages. One page is a JPanel (A) that holds pages contents. Onto that