awt

Automatically find frame sizes from png sprite sheet [duplicate]

一世执手 提交于 2019-12-22 18:31:58
问题 This question already has an answer here : Closed 6 years ago . Possible Duplicate: PySide: Separating a spritesheet / Separating an image into contiguous regions of color Given a .png image with transparent pixels and a grid of individual animation frames (where the last row need not be full), how would you automatically find the dimensions of each individual frame, and detect how many frames are in the .png? I am trying to convert the resources from the creative-commons treasure-trove of

KeyListener - do I need to call the keyPressed Method in my main?

痞子三分冷 提交于 2019-12-22 11:37:31
问题 Here is what's inside my keyPressed : public class Movie extends JFrame implements KeyListener { public static Sprite star1 = new Sprite("Assets/star1.png"); public static Sprite star2 = new Sprite("Assets/star2.png"); public static Sprite star3 = new Sprite("Assets/star3.png"); public void init(){ this.addKeyListener(this); } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub } @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub }

Get all swing components in a container

南楼画角 提交于 2019-12-22 11:21:02
问题 I think we can use jScrollPane.getComponents() to get awt components of a jscrollpane. My question is: is there a way to get swing components of a container some how? 回答1: All Swing components extend JComponent. Component[] comps = jScrollPane.getComponents(); ArrayList<JComponent> swingComps = new ArrayList<JComponent>(); for(Component comp : comps) { if(comp instanceof JComponent) { swingComps.add((JComponent) comp); } } 回答2: You can call getComponents then test to see if it is an instance

Printing in Java using PS file

做~自己de王妃 提交于 2019-12-22 10:39:21
问题 I have a generated post script file and want to print using it. How can it be achieved in java either using javax print API or AWT. Is it possible? 回答1: Complicated. Does your printer(s) support PostScript? Is it networked? If so, most networked printers can talk LPR and you can shove the file over as-is. On Windows, you could also stream the file as-is to the lpt1: mapped port via something like NET USE LPT1: \\[Computer Name]\Printer /PERSISTENT:YES . If you're on a server and you do lots

Java custom Paint implementation performance issue

只愿长相守 提交于 2019-12-22 09:20:21
问题 I'm using Java to create a game, and I'm using TexturePaint to texture areas in the background. Performance is fine using java.awt.TexturePaint, however, I want to have areas having an inherent rotation, so I tried implementing a custom Paint called OrientedTexturePaint: public class OrientableTexturePaint implements Paint { private TexturePaint texture; private float orientation; public OrientableTexturePaint(TexturePaint paint, float orientation) { texture = paint; this.orientation =

Using JSplitPane with an AWT component

不问归期 提交于 2019-12-22 08:41:32
问题 I have an AWT canvas which I cannot convert to a Swing component (it comes from VTK). I wish to display a few of these canvases inside of a JSplitPane. I've read about mixing heavy and light weight components in Java and know that it's a pain in the butt, but I don't have a choice. If I wrap the AWT canvas inside of a JPanel and then put that on the split pane the split pane doesn't function at all. However, if I put the AWT canvas inside of a JPanel and then that inside of a JScrollPane and

Need FileDialog with a file type filter in Java

冷暖自知 提交于 2019-12-22 08:18:55
问题 I have a JDialog with a button/textfield for the user to select a file. Here's the code: FileDialog chooser = new FileDialog(this, "Save As", FileDialog.SAVE ); String startDir = saveAsField.getText().substring( 0, saveAsField.getText().lastIndexOf('\\') ); chooser.setDirectory(startDir); chooser.setVisible(true); String fileName = chooser.getFile(); My problem is that instead of seeing an All Files filter, I want to provide a custom filter, e.g. for Word docs or something. I setup a custom

KeyListener in Textfield not firing when press enter

陌路散爱 提交于 2019-12-22 06:45:04
问题 I'm trying to make a program that can converts fahrenheit to celcius in java. In program i have 2 Labels and 1 TextField for input. I want to make convert temperature when user types the temperature and presses Enter . To do that, i added a key listener to my textfield but it doesn't work. When i press Enter listener don't fire at all. And here's my code. public class TempConv extends JFrame{ private JLabel info; private JLabel result; private JTextField input; private String outcome; public

The Elegant way to handle Cyclic Event in Java?

房东的猫 提交于 2019-12-22 05:50:24
问题 i think this not a specific problem to me; everybody might have encountered this issue before. To properly illustrate it, here's a simple UI: As you can see, those two spinners are controlling a single variable -- "A". The only difference is that they control it using different views. Since these two spinners' displaying values are synchronized, cyclic event shows up. If i change the top spinner, "A" will be changed and the bottom spinner's value will also be updated accordingly. However ,

Java check if Checkbox is checked

安稳与你 提交于 2019-12-22 05:37:08
问题 I use: CheckboxGroup cg = new CheckboxGroup(); Checkbox c1 = new Checkbox("A", false, cg); Checkbox c2 = new Checkbox("B", false, cg); Checkbox c3 = new Checkbox("C", true, cg); To create a group of three checkboxes. Now, I want to check which one of them is checked. I use: if (c1.isSelected()) { } but this gives The method isSelected() is undefined for the type Checkbox ... Recommended solution is add cast to c1, I do so and it gives Cannot cast from Checkbox to AbstractButton ... Again, how