awt

Using CardLayout in Java

落爺英雄遲暮 提交于 2019-12-31 04:11:11
问题 I'm currently trying to make a game with a menu. Menu looks like this. http://puu.sh/xGoC Ideally, when I push a button, it will bring me to the game. The game looks like this. http://puu.sh/xGoV I currently initialize a JFrame() in my main class which runs either the menu class or the game class (Both of which are JPanels). How would I go about using CardLayout to make it so that I can initialize the game menu and when I click a button, change the panel to the game panel? 回答1: I've got some

How to display floating tool tip text on a polygon

為{幸葍}努か 提交于 2019-12-31 03:57:09
问题 I have written a Java code to draw a polygon on an image. When I put my cursor inside the polygon it prints "Inside" otherwise "Outside". So the detection of the points inside the polygon is working fine. But I want to implement the effect of setToolTipText inside the polygon i.e. at the time of mouse hover inside the polygon, it will show the floating text "Inside". Similar to the effect in this image: http://www.java2s.com/Code/Java/Swing-JFC/WorkingwithTooltipText.htm What are the minimal

Desktop TCP Streaming (java)

核能气质少年 提交于 2019-12-31 02:45:28
问题 I want to stream desktop screen captures using sockets. I don't know the exact way to do this, so I went with AWT's robot :) Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); The problem is that images coming from the robot are too large to make a stream. A 1440x900 capture is about 0.3MB and I can't transfer it fast enough to create a smooth 24fps stream. Currently I'm using a TCP socket, because I had problems cutting down the image into multiple

Java swing. How to wait for other Jframes

妖精的绣舞 提交于 2019-12-31 01:44:38
问题 In a JFrame, when I click on 'login', I pop up another Jframe which is the login window. How do I make my main Jframe wait for my login Jframe to exit, before doing anything else? 回答1: Just use a modal dialog in stead of a frame, that way you cannot do anything else until it'is closed see http://mindprod.com/jgloss/modal.html for explanation and see http://www.java2s.com/Tutorial/Java/0240__Swing/ASimpleModalDialog.htm for code example If you insist on using a JFrame, you could use a

Stop Fullscreen Window from minimizing when JOptionPane.showMessageDialog?

你。 提交于 2019-12-31 01:14:11
问题 The Code private MainApp() /* Extends JFrame */{ DisplayMode displayMode = new DisplayMode(800, 600, 16, 75); ScreenManager.setFullScreenWindow(displayMode, this); } The Problem Whenever I call: JOptionPane.showMessageDialog(MainApp.getInstance(), "Test Message Box"); The Window minimizes for some reason, then I have to re-activate it. The Message Box shows after I re-activate the Window. The Question Is there any way to stop the Fullscreen Window from minimizing when I call the Message Box?

Drag/Moving a shape around jPanel

允我心安 提交于 2019-12-30 10:44:18
问题 Yesterday I ask a question about how to draw a bounding box to hold a shape inside and how to drag and drop that selected shape . The first question is solved. But I'm having some trouble to move the shape. Is there any especific transformations to move a shape around the jPanel? I have this code: public boolean drag(MouseEvent e) { if(points.isEmpty()) //if point's vector is empty return false; if(!selected) return false; int x = e.getX(), y = e.getX(); if (!dragging) lastMovePoint

Loading some TrueType Font from TTF file in Java causes FontFormatException: Font name not found

时间秒杀一切 提交于 2019-12-30 10:20:07
问题 I am attempting to create a java.awt.Font instance from a TTF file on my system, but only some fonts are able to load without error. The code below is some test code I found online. When run on my system, it is able to load 285 fonts successfully (ex. Arial.ttf), but fails on 83 fonts, (ex. AmericanTypewriter.ttf). All errors are of the form FontFormatException: Font name not found with no embedded cause. Are there known issues with java.awt.Font and format compatibility? I can't find

CardLayout, switch between JPanels by ButtonClick

泪湿孤枕 提交于 2019-12-30 07:10:27
问题 I want to switch between JPanels by clicking buttons on the JPanels. For example: I have a JPanel sim with a JButton simknop and a JPanel help with JButton helpknop I want to switch between these 2 JPanels by clicking the buttons. When I click JButton simknop JPanel help should appear and when I click JButton help JPanel sim should appear. Below you can find the different classes: main.java public class main extends JFrame { JPanel cards; sim sim; help help; public main() { this.setSize(1024

Drawing lines with mouse on canvas : Java awt

元气小坏坏 提交于 2019-12-30 06:27:14
问题 The attempt is to enable drawing of figures(a line for now) with mouse on the awt canvas . Iam trying out java graphics for the first time . So not sure how to go about it . This is my first attempt : package def.grafi; import java.awt.Canvas; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Dra {

Create transform to map from one rectangle to another?

回眸只為那壹抹淺笑 提交于 2019-12-30 04:33:30
问题 What is the simplest way to create AffineTransform which maps coordinates from one rectangle to another (float/double rectangles are given)? UPDATE 1 Rectangles can be absolutely different. For example [(0,0)-(1,1)] and [(150,-14)-(-1000,-14.1)]. And transformation should transform uniformly. For example, rectangle corners should be transformed one to one. For example coordinates (0,0) should turn to (150,-14). UPDATE 2 I need AffineTransform object, not just calculation. Because I want to