awt

ActionListener for JLabel

蓝咒 提交于 2019-12-18 03:40:26
问题 I want to learn how to write an ActionListener for JLabel . I want to make a label that open a new frame for user when user clicks the label. Maybe MouseListener can work but I do not know how to make it. 回答1: I recommend using a JTextField rather than a JLabel for this use. Being based on a component designed to be focusable, it allows an ActionListener and looks and feels more like an HTML link. E.G. That is how it appears when the mouse is hovering over the first link. LinkLabel /* License

Why bother with setting the “sun.awt.exception.handler” property?

人走茶凉 提交于 2019-12-18 03:38:45
问题 Here's some code that catches an exception thrown on the Event Dispatch Thread: package com.ndh.swingjunk; import java.awt.EventQueue; import javax.swing.JFrame; public class EntryPoint { public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler()); // System.setProperty("sun.awt.exception.handler", MyExceptionHandler.class.getName()); EventQueue.invokeLater(new Runnable() { public void run() { new SomeWindow("foo").setVisible(true); } }); } }

java黑客帝国数字雨特效源码

。_饼干妹妹 提交于 2019-12-18 00:56:19
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.image.MemoryImageSource; import java.util.Random; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.Timer; public class Rain extends JDialog implements ActionListener { private Random random = new Random(); private Dimension screenSize; private JPanel graphicsPanel; //行高,列宽 private final static int gap = 20; //存放雨点顶部的位置信息(marginTop) private int[] posArr; //行数

How to add to this round button metal background in java?

二次信任 提交于 2019-12-17 21:36:12
问题 How to give this button background to be as jbutton i want to give this button metal color or grediant color how to make that? import java.awt.*; import java.awt.event.*; RoundButton - a class that produces a lightweight button. Lightweight components can have "transparent" areas, meaning that you can see the background of the container behind these areas. @SuppressWarnings("serial") public class RoundButton extends Component { ActionListener actionListener; // Post action events to listeners

Why is my line not drawing?

。_饼干妹妹 提交于 2019-12-17 21:24:04
问题 So I have defined a mouseEventlistener and mousemotionListener to define points as so. protected Point elementPosition = null; public Point endPoint = null; public Axis tempAxis; public Graphics g; class MouseButtonHandler extends MouseAdapter { public void mousePressed(MouseEvent e) { if(e.getModifiers()==InputEvent.BUTTON1_MASK) { elementPosition =new Point(e.getX(), e.getY()) ; if(addType==YLABEL) { YDialog ydia = new YDialog(anApp); ydia.setVisible(true); value =(double) ydia.getValue();

Im not sure how to get the data from my text field

心已入冬 提交于 2019-12-17 21:21:24
问题 I want to get the data from my textfield and set it to int h. and have that change the size of the rectangle im drawing, but im not sure how to go get the data from the textfield, I tired using e.getsource in actionperfomred but it cannot find my textfield. My code is below: import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import javax.swing.*; import java.net.*; import java.sql.*; import java.lang.Object; import java.awt.Graphics;

ActionListeners, multiple field updates, and reloading user GUI selections from a file

耗尽温柔 提交于 2019-12-17 21:14:23
问题 I have multiple places where I convert between one coordinate system and another. In each case there is a cosine/sine calculation between, let's call them x, y and x', y'. These are all JFormattedTextFields. If the user enters a value in any of the 4, an ActionListener is called. Lets call the fields fieldx, fieldy, fieldx1, and fieldy1. If the user enters anything in fieldx or fieldy, I HAD keyboard and focus listeners (the same one for all four fields) that would update fieldx1 and fieldy1

Detect current screen bounds

允我心安 提交于 2019-12-17 20:56:18
问题 I am working on an application that has setDecoration(false) and I have a MouseMotionlistener so I can move it around, and at the moment I am trying to make a maximize button. On the default monitor it works perfectly, but on a second monitor if I click the maximize button it will maximize to the default screen. How would I get the X & Y coordinates of the screen the application is currently on? I.E. I have 2 monitors both at 1600x900, so if the application is on monitor 1, the X & Y would be

How to check for key being held down on startup in Java

依然范特西╮ 提交于 2019-12-17 20:07:37
问题 I'm trying to write a resolution selection dialog that pops up when a program first starts up. To prevent boring the user, I want to implement the fairly standard feature that you can turn off that dialog with a checkbox, but get it back by holding down the alt key at startup. Unfortunately, there is no obvious way to ask java whether a given key is currently being pressed . You can only register to be informed of new key presses via a KeyListener, but that doesn't help if the keypress starts

How to implement oval GradientPaint?

不问归期 提交于 2019-12-17 19:53:20
问题 We know that there are a class named RadialGradientPaint in Java and we can use it to have a gradient painting for circle. But I want to have an oval (ellipse) GradientPaint . How to implement oval GradientPaint ? 回答1: Use an AffineTransform when drawing the RadialGradientPaint . This would require a scale instance of the transform. It might end up looking something like this: import java.awt.*; import java.awt.MultipleGradientPaint.CycleMethod; import java.awt.geom.*; import java.awt.event.*