awt

JavaFX app in System Tray

孤街醉人 提交于 2019-11-26 16:16:02
问题 I am Making a Simple App using JavaFX UI, The app simply just do that: has a systray icon, which when clicked shows a window, when clicked again hides it, on rightclick shows a menu with 1 "exit" item I already Made the UI and put the App in the Sys Tray, but i can't show/hide it using Normal Actionlistener method, but i got this error: Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0 here is the Code:

How to define multiple JButton actions from a different class

℡╲_俬逩灬. 提交于 2019-11-26 15:33:58
I am writing a program where I need to do different actions for a separate class depending on which button is clicked. public class NewJFrame{ public static JButton b1; public static JButton b2; public static JButton b3; } public class Slot{ int value; JButton button; Slot(int value, JButton button) { this.value=value; this.button=button; } } public class Game{ Slot[] slots=new Slot[3]; Game(){ slots[0]=new Slot(1,NewJFrame.b1); slots[1]=new Slot(2,NewJFrame.b2); slots[2]=new Slot(3,NewJFrame.b3); } public void actionPerformed(ActionEvent e) { for(int i=0;i<3;i++){ if(e.getSource()==slots[i]

paintComponent() vs paint() and JPanel vs Canvas in a paintbrush-type GUI

删除回忆录丶 提交于 2019-11-26 15:27:51
I got some interesting ideas and criticism from this , this and this post (see last post for the code of the GUI in question). Nevertheless, I'm still quite confused about some things. Mainly, what is the least expensive way of displaying user-introduces graphics? More specifically, I used a paintComponent() method from JPanel class by making an object of this class in the MouseDragged() method together with paintComponent(getGraphics()) method ( AuxClass2 and AuxClass1 accordingly). Apparently, using getGraphics() and paintComponent() instead of repaint() are bad ideas, I suspect something to

How to draw a tree representing a graph of connected nodes?

你说的曾经没有我的故事 提交于 2019-11-26 15:27:14
I want to display a tree in a Java GUI, but I dont know how. The tree represents a graph of connected nodes, like this: I should say that I have my own tree class: public class BinaryTree { private BinaryNode root; public BinaryTree( ) { root = null; } public BinaryTree( Object rootItem ) { root = new BinaryNode( rootItem, null, null ); } public BinaryTree( Object rootItem,BinaryNode a,BinaryNode b ) { root = new BinaryNode( rootItem, a, b ); } public int leavesCount(){ return BinaryNode.leavesCount(root); } public boolean equal(BinaryTree a,BinaryTree b){ return BinaryNode.equal(a.root, b

Fahrenheit to Celsius conversion yields only 0.0 and -0.0

三世轮回 提交于 2019-11-26 14:47:59
问题 I'm on the 8th chapter (Methods, Constructors, and Fields) of my Java methods book and I'm having a problem with one of my exercises. The provided code is Temperature.java import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.text.DecimalFormat; public class Temperature extends JApplet implements ActionListener { private JTextField displayF, displayC; private static DecimalFormat displayFormat = new DecimalFormat("0.0"); public void init() { Container c =

What does .pack() do?

流过昼夜 提交于 2019-11-26 14:41:55
I am learning about JPanel and GridLayout , this snippet of code will produce a simple JPanel with 6 buttons package testing; import java.io.*; import java.util.*; import java.security.*; import javax.xml.bind.DatatypeConverter; import java.lang.*; import java.awt.*; import javax.swing.*; public class Testing { public static class GridPanel extends JPanel { public GridPanel() { setLayout(new GridLayout(2,3)); setBackground(Color.GREEN); this.setPreferredSize(new Dimension(500,500)); JButton b1 = new JButton ("Button 1"); JButton b2 = new JButton ("Button 2"); JButton b3 = new JButton ("Button

Image/Graphic into a Shape

孤人 提交于 2019-11-26 14:41:32
I was wondering whether there is any way to convert an image/graphic into a Shape ? For example, can I convert the outline of a motorcycle shape into a Shape so I can then use it in Java? I know you can do it with normal squares or with rounded corners, polygons, etc. But is there a way to do a custom shape? motorcycle.jpg motorcycle-03.png ImageOutline.java This code requires some patience (when running). import java.awt.*; import java.awt.image.BufferedImage; import java.awt.geom.Area; import javax.imageio.ImageIO; import java.io.File; import java.util.Date; import javax.swing.*; /*

formatting text in jdialog box

ε祈祈猫儿з 提交于 2019-11-26 14:40:10
问题 I have a JOptionPane: JOptionPane.showMessageDialog(null, text); The text is a sting: String text = "Hello world." What I want to do is change the color of the text, specifically a single word, lets say 'Hello'. SO what I've tried is: String t1 = "Hello"; String t2 = "world." Font serifFont = new Font("Serif", Font.BOLD, 12); AttributedString as = new AttributedString(t1); as.addAttribute(TextAttribute.FONT, serifFont); as.addAttribute(TextAttribute.FOREGROUND, Color.red); JOptionPane

Using addMouseListener() and paintComponent() for JPanel

偶尔善良 提交于 2019-11-26 14:33:01
问题 This is a follow-up to my previous question. I've simplified things as much as I could, and it still doesn't work! Although the good thing I got around using getGraphics() . A detailed explanation on what goes wrong here is massively appreciated. My suspicion is that something's wrong with the the way I used addMouseListener() method here. EDIT completely rewrote the code. Still does not work properly though. import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent;

Is it safe to construct Swing/AWT widgets NOT on the Event Dispatch Thread?

泄露秘密 提交于 2019-11-26 14:29:15
I've been integrating the Substance look and feel into my application and ran into several problems regarding it's internal EDT (Event Dispatch Thread) checking routines. Substance absolutely refuses to construct UI classes outside of the EDT. I've done plenty of Swing/AWT and I know most of the rules regarding the EDT. I use SwingWorker, SwingUtilties.invokeLater to modify components. I always though that components could be CONSTRUCTED outside of the EDT, but must be realized and manipulated on the EDT. In other words, you can construct and setup defaults in the background but the call to