jlabel

How to open this program on a window?

余生颓废 提交于 2019-12-13 10:26:59
问题 Can anyone help me with my if and else statements? It's only saying "Exit Goodbye" whenever I input something, which should only happen when I enter -0. My teacher is gone for the week, so I don't have anyone to ask for help. package game; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Random; import javax.swing.JOptionPane; public class GameFrame { /** * @param args */ public static void main(String[] args) { // num1 - Variable to store the first value //

java exception in thread “AWT-EventQueue-0” java.lang.IllegalArgumentException

北城以北 提交于 2019-12-13 08:07:16
问题 I was trying my first code in java swing and got many errors. my code is: import java.awt.*; import java.awt.event.*; import javax.swing.*; class Swinging extends JFrame { JTextField ans; int count =0; static final long serialVersionUID = 1L; Swinging() { Container cp= getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JLabel("value",7)); ans=new JTextField("0",10); cp.add(ans); JButton inc= new JButton("increment"); cp.add(inc); inc.addActionListener(new ActionListener(){ public

Laying grids above images

巧了我就是萌 提交于 2019-12-13 08:03:14
问题 What I have implemented till now in java is ask the user to upload an image from the directory. My next step is that when the image is loaded a grid is placed above that image just for visual purpose so that the image gets divided in a, say 10 x 10 grids. How do I implement this stuff? Here's what I have implemented till now. JFileChooser choose=new JFileChooser(); choose.showOpenDialog(null); File f=choose.getSelectedFile(); String filename=f.getAbsolutePath(); path.setText(filename);

How do I detect the collison of components?

你。 提交于 2019-12-13 07:09:17
问题 How do I detect the collision of components, specifically JLabels (or ImageIcons?)? I have tried this: add(test1); test1.setLocation(x, y); add(test2); test1.setLocation(x1, y1); validate(); if(intersects(test1, test2)) { ehealth-=50; } public boolean intersects(JLabel testa, JLabel testb) { boolean b3 = false; if(testa.contains(testb.getX(), testb.getY())) { b3 = true; } return b3; } When I run this, it does nothing! I used to use Rectangle , but it didn't go well with me. I was thinking

Is it possible to calculate JTextFields into a JLabel as they are being typed? [closed]

北城余情 提交于 2019-12-13 04:29:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . Is it possible to calculate a group of JTextFields as they are typed in and set the result to a JLabel? For Example: int iCalc = 0; JTextField x = new JTextField(); JTextField y = new JTextField(); JTextField z = new JTextField(); JLabel lCalc = new JLabel("Your total is: " + calc); As i am typing, calc gets

Implementing a simple hover effect on a Jlabel

元气小坏坏 提交于 2019-12-13 04:03:13
问题 I am messing around with some ideas for a side project and I would like to create a GUI using Java swing that doesn't look like it is from Windows95. One of the ideas I was kicking around was to use JLabels as buttons instead of the standard JButton. This would allow me to customize hover, drag, and movement effects as I like. Research into the MouseAdapter class should allow me to do everything I intend, unfortunately I am having some trouble implementing the hover effect as I wanted as the

Change jLabel Visibility

别等时光非礼了梦想. 提交于 2019-12-13 03:47:53
问题 I am new to Netbeans and Java and am having an issue with jLabels that are on jPanels. I have a jTabbedPane with a jPanel in it. I have a jLabel on the jPanel. I would like to set the visibility of the jLabel to false, but it does not seem to work. The label is still visible when I run the program. I do not understand why. Label label = new Label("jLabel1"); label.setVisible(false); 回答1: You can set it inside initComponents() ; package my.tt; public class NewJFrame extends javax.swing.JFrame

JLabel text being cut off

喜你入骨 提交于 2019-12-13 01:19:03
问题 As you can see from the image above some of the text is being cut off :( Code: package malgm.school.clockui.ui; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import javax.swing.*; import malgm.school.clockui.ClockUI; import malgm.school.clockui.ResourceLoader; public class ClockFrame extends JFrame { private static final long serialVersionUID = 1L; public final static int FRAME_WIDTH = 600; public final static int FRAME

Draw Line in a JLabel and add as JPanel in a JFrame does not function

青春壹個敷衍的年華 提交于 2019-12-13 00:38:24
问题 im very new in Java so sorry for any stupid question. Here is my problem: I just want to draw a line - if I add the JLabel Myline() directly as label to the JFrame MyFrame , then it will be showing in the resulting JFrame -Dialogwindow, but if I add MyLine() to the JPanel panel and panel to MyFrame then there is no Line. Why? package examples; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt

Setting Font and Colors to different parts of String that is contained in one JLabel

我是研究僧i 提交于 2019-12-12 23:07:25
问题 How should I do that for this String ? Orb of Deception Range: 880 Cooldown: 7 Cost: 70/75/80/85/90 Mana I want to have color blue and size 14 for "Orb of Deception" , and "Range" / "Cooldown" / "Cost" color black size 12, and the numbers color green and size 10. It must be contained in one JLabel . Is this possible? 回答1: E.G. (adjust to need) import java.awt.*; import javax.swing.*; class ColoredLabel { static String text = "<html>" + "<head>" + "<style type='text/css'>" + ".name {" + " font