awt

custom shape rotation issue

不问归期 提交于 2019-12-02 17:46:20
问题 I am trying to rotate a custom shape around its center, but can not get the result as expected. what i want is * shape should be rotated around its center without moving itself. * what my solution is currently doing is rotating a whole shape around its center , by every rotation its changing its position. I have multiple shapes so i have created a class to encapsulate a shape with its transform in following class public abstract class Shoe implements Shape, ShoeShape { // variable declaration

i can't see circle moving

白昼怎懂夜的黑 提交于 2019-12-02 17:05:43
问题 While using Swing in java, I am trying to move a circle slowly from a starting position to an end position when clicking a button. However, I can't see the circle moving. It just moves from start to end in an instant. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MyApp { private int x = 10; private int y = 10; private JFrame f; private MyDraw m; private JButton b; public void go() { f = new JFrame("Moving circle"); b = new JButton("click me to move circle"); m

How to monitor Event Dispatch Thread queue?

社会主义新天地 提交于 2019-12-02 15:51:09
问题 I have a heavy java project which does not work responsive to the users. I have found out that long time needed events in event dispatch thread can cause my project to work slowly. So, I have two question in this manner: How can I monitor the event dispatch thread and see which events are in the queue and eventually, which ones spend more time in event dispatch thread? ( As you know invokeLater function insert the event to the end of the event dispatch queue. I want to monitor whole event

add items runtime on combobox in java

六月ゝ 毕业季﹏ 提交于 2019-12-02 15:21:15
问题 I have created a comboBox in Swing and I want to add items on it in another function. But the problem is that items are not displaying after calling that function: public void addItems() { combo.addItem(""); // i want to add items here when this function is being called // but those items are not displaying after calling this function // i m calling this function on button click } 回答1: Works for me in this SSCCE: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt

Embedding a JFrame in an Applet

十年热恋 提交于 2019-12-02 15:08:37
问题 I have found an open source application that creates a JFrame to display some content. I would like to "embed" this JFrame into an applet, so everything that is displayed in the Jframe will be displayed in the applet - is this possible? Thanks for your help! 回答1: Create an instance of the frame. Get the content pane of the frame. Add the content pane to the applet. 回答2: ..open source application that creates a JFrame.. Since the source is available, take whatever they do in the frame, and do

How to get the bars in a bar chart start from the x-axis in java? [closed]

淺唱寂寞╮ 提交于 2019-12-02 14:54:40
As you can see in the picture, the bars in the chart starts below the x-axis. How do I fix it so that it starts from the x-axis line? Please suggest me a fix and also I would be helpful to know where I am going wrong. private int PAD = 20; private int LPAD = 35; private int DPAD = 25; Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.BLACK); String DataString[] = dataset.split(", "); double DataArray[] = new double[DataString.length]; double MaxValue = 0; int w = getWidth(); int h = getHeight(); for (int i = 0; i < DataString.length; i = i + 1) { try { double out = Double.parseDouble

Get Click Count Mouse Listener on Touch Screen

雨燕双飞 提交于 2019-12-02 14:37:58
问题 Im running a simple JFrame with a JList. I encountered an issue just like this guy> Java getClickCount on touchscreen I know it has been posted already but there were no answers. jList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("MouseClick: "+e.getClickCount()); if (e.getClickCount() == 2) { 回答1: Code below is working.. public class MainTest extends JPanel { public MainTest() { addMouseListener(new MouseAdapter() { public void

Adding a button component to a java tabbed pane in java

爱⌒轻易说出口 提交于 2019-12-02 13:59:55
问题 i am trying to create GUI using java swings.I am just a beginner in java swings. My primary idea was to create two tabs and add a button in one of the tabs. I wanted to write a separate class for each tab so i created 3 classes out of which one has the main method.and the other two represent the tabs. In one of the tabs i wanted to add a button in middle and add an action listener to that button. below is the class which has the main method. public class abc { JFrame frame; JTabbedPane

What are the UIManager keys for JFileChooser and FileDialog?

大兔子大兔子 提交于 2019-12-02 13:48:24
问题 I want to use the UIManager.get method in order to get and save the system look and feel for JFileChooser and FileDialog and then I want to change the look and feel. The problem is that I don't know what are the keys for Swing components that UIManager.get method uses. Is there any reference or any convention for that? Thanks 回答1: UIManager Defaults 来源: https://stackoverflow.com/questions/3974743/what-are-the-uimanager-keys-for-jfilechooser-and-filedialog

Is it possible to know whether the copied content in clipboard is mp3 file using awt.Toolkit and Clipboard in java

╄→尐↘猪︶ㄣ 提交于 2019-12-02 13:36:41
I am trying to write a code which runs at background and monitors the copy actions for copying a .mp3 file or a folder containing a .mp3 file { Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); if (cb.isDataFlavorAvailable(DataFlavor.javaFileListFlavor)) { try { String name = ""+cb.getData(DataFlavor.javaFileListFlavor); boolean found = false; if (name.toLowerCase().endsWith(".mp3]")) { System.out.println("Is MP3"); found = true; } if (!found) { System.out.println("Is not MP3"); } } catch(UnsupportedFlavorException ex) { ex.printStackTrace(); } catch(IOException ex) { ex