awt

Java: wait first frame while retrieving data from second frame then on hitting on close button and control also come to the first frame

荒凉一梦 提交于 2019-12-13 02:25:36
问题 In my application two frame is there. In main frame "Server" button is there. When I click on "Server" button second frame will open and after enter some detail when i click on "submit" button which is on second frame this frame will close and control again go to the "Server" button where I call this frame so I will do my rest of task. And one more thing I want in my application when the second frame is open then no activity is on first frame. My first frame is: JFrame frame; In this frame

How to rotate a line based on a given number of degrees

纵饮孤独 提交于 2019-12-13 02:15:20
问题 I have a line drawn with a Graphics object. I want to rotate this line a certain amount of degrees based on how much the mouse is dragged. I can get the number of degrees i need to rotate it but how do i then rotate the line based on that? Thank You! 回答1: You can create a Line2D object for your original line. Then you can use AffineTransform#getRotateInstance to obtain an AffineTransform that does the rotation about a certain angle, around a certain point. Using this AffineTransform , you can

AWT paints only last-added Canvas

无人久伴 提交于 2019-12-13 00:45:52
问题 I've a VERY simple AWT Painting. Just playing aound to make something bigger. But can't get it working ... What happens is that only elypse2 is shown - regardless of repaint()ing it or not. I also tried to use Swing components instead of AWT (JFrame, JComponent) but this also changes nothing. Is using a Layout Manager necessary? But I want to draw only graphical components, like arcs, rectangles, line, poly-lines, aso ... Here's the main(): public static void main(String[] args) { Frame

Haxe Java windowing

大城市里の小女人 提交于 2019-12-13 00:41:27
问题 In the Haxe.java api at http://api.haxe.org/java/index.html, there does not appear to be any support for graphics, windowing, or user-interactive events. There used to be: http://old.haxe.org/doc/java/graphics2d (note the "old"), but we can't use these libraries anymore: import java.awt.Graphics; // Compile time error: Class not found : java.awt.Graphics. import java.awt.*; // this works, but so does import java.nonExistantPackage.*; Does Haxe still have java graphics support? If so, how can

Prevent robot.mouseMove to generate a MouseEvent?

自闭症网瘾萝莉.ら 提交于 2019-12-12 19:33:37
问题 I have a 3D game, and every time I move the cursor, I want it to reset to the middle. Problem is that robot.mouseMove() calls MouseEvent (It does make sense) and resets the position and so I can't rotate. Thank you! 回答1: Because Robot is generating a native event, the event will (eventually) make it's way to the Event Queue for processing by the EDT. This means if you try and do something like... removeMouseListener(...); Robot.mouseMove(...); addMouseListener(...); It will, basically, have

How to correctly update an Image in a JLabel?

被刻印的时光 ゝ 提交于 2019-12-12 19:26:28
问题 I'm French so my English is quite bad but I have a real problem with java: I'm trying to show an Image built manually with some fillRect & co. It works. Next, I want to update this image as a function of the text I enter in the text field. And there is the problem: it doesn't change anything, and if I manually rescale the window of the JFrame , the image shows totally deformed or scaled badly. I'm a beginner and I have difficulties with GUI, moreso when I want to couple it with Images. Can

Jframe setDefaultCloseOperation not working

痞子三分冷 提交于 2019-12-12 18:22:45
问题 import javax.swing.*; import java.awt.*; class Myframe extends Frame { private JButton btn; private JTextArea txtarea; Myframe() { super("Saibaba"); setLayout(new BorderLayout()); btn=new JButton("CLICK Me"); txtarea=new JTextArea(); add(txtarea,BorderLayout.CENTER); add(btn,BorderLayout.SOUTH); setSize(500,600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //this isnt working. setVisible(true); } public static void main(String args[]) { Myframe m=new Myframe(); } } Why is this

How do I nest layout managers without using swing classes/methods?

橙三吉。 提交于 2019-12-12 18:11:51
问题 I need to make an applet in Java 6, 640*480 pixels, with a toolbar on the bottom with some buttons, scrollbars, and labels. The best way I could think of was using a BorderLayout , making the BorderLayout.SOUTH region a GridBagLayout (which would contain the controls), and the rest of the BorderLayout area null, as a place for grapics to be drawn with the controls. I can't find any resources online that don't use swing, and I don't know anything about swing to deduce what they are doing or

Java GetFile returns incorrect filename after using SetFile

♀尐吖头ヾ 提交于 2019-12-12 16:09:50
问题 I have some Java code: public static String getSaveFilePath(String title2) { FileDialog fd = new FileDialog(new Frame(), "Save As...", 1); fd.setFilenameFilter(new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".mp3"); } }); fd.setFile(title2 + ".mp3"); fd.setVisible(true); String str3 = fd.getFile(); String str4 = fd.getDirectory(); if (str4 == null) return null; str3 = str3.replace(".mp3", ""); str3 = str3 + ".mp3"; String str5 = str3; File localFile

draw graphics outside of paint method

会有一股神秘感。 提交于 2019-12-12 15:15:37
问题 private void draw_shape() { Graphics g = getGraphics(); g.drawLine(0, 0, 100, 100); repaint(); } In paint method only those graphics are drawn which is a part of paint method because of which I wanted to draw shapes outside of paint method. This code draws the line but it immediately disappeares, I don't understand why this is happening. please help 回答1: This doens't work because you are getting the current Graphics outside of the Swing repaint thread. Basically: you get the current Graphics