awt

Canvas fillRect() not filling defined canvas

笑着哭i 提交于 2019-12-12 07:27:56
问题 I am extending a Canvas and adding it to a JFrame . I understand that AWT and Swing should not be mixed and that drawing on JPanel is preferred but i'm trying to follow a game engine tutorial and i'd like to stick to it since I got it working so far. The Canvas has minimumSize , maximumSize , and prefferedSize set to the dimensions of 550, 400 . When I do a draw call graphics.draw(0,0,550,400) it doesn't fill the entire screen as it should. I changed the draw call to graphics.draw(0,0,560,410

Get key combinations

一曲冷凌霜 提交于 2019-12-12 07:18:34
问题 How can I get key combination of keys on keyboard E.G. ( Ctrl + somekey , Alt + somekey ) with Java? I use KeyEvent listener, MouseEvent listener for all keys on keyboard. I can catch all key event on keyboard by using that listener. But, I cannot catch key combination such as ( Ctrl + Alt + Del )....etc. 回答1: public void keyPressed(KeyEvent kevt) { if(kevt.getKeyChar()=='c') { if(kevt.isAltDown()) //Code if Alt+c pressed if(kevt.isControlDown()) //Code if Ctrl+c pressed if(kevt.isShiftDown()

Add image to panel not using swings [closed]

余生颓废 提交于 2019-12-12 06:46:12
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . how to we add bitmap image in panel and then get the graphics that the image is using and tell the panel to draw a line using the same graphics inside the image. 回答1: Basic painting is done by a Swing components

Screenshot capture in Window 8 OS

半世苍凉 提交于 2019-12-12 06:45:48
问题 To capture screen shot in my java application i have write following code Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage capture = new Robot().createScreenCapture(screenRect); ImageIO.write(capture, "png", new File("resources/img/screenshot.png")); This is working successfully and capture screen shot but this is not working in windows 8 operating system. any one else who have face this type of problem and get soluction? 回答1: my application is

Swing - Drop down Panel

≯℡__Kan透↙ 提交于 2019-12-12 06:37:27
问题 I am working on Java Swing, making an UI. I have a Panel (Panel 1) with information, and I want to create a dropdown menu, but not like de comboBox. Is hard to explain. I see the panel, and in the bottom, I have a button. When I press this button, I want to make appear another panel (transparent) on Panel 1. I dont know how can I do that.I wait for yoir help, if I have explained it well. I dont want the typical dropdown list, is like a dropdown panel. EDIT: for example, in the main page of

How to get an instance of java.awt.Graphics in a java.applet.Applet?

可紊 提交于 2019-12-12 06:36:21
问题 I am currently coding the game of Snake for my computer science class. However, I ran into a lot of difficulties (since I am the only one in my block that is working alone) and I had to restart. Right now I am just trying to make an array of objects (named Snake) from the second class (Segment) I made. I get a NullPointerException on line 26: g.fillRect(xValue, yValue, size, size); Where should I get an instance of Graphics to call this method on? import java.awt.*; import java.applet.*;

TextBox not displaying on frame until the frame is stretched manually

ぃ、小莉子 提交于 2019-12-12 06:10:21
问题 I am trying to create a login page. I wrote code for two textboxes and one button. One textbox next to Username and other one next to Password. One "Sign In" button below. But I am not sure why the textbox's and button are not shown on my output. I only get the Username and password label's on my ouput screen. Strange thing is whenever I stretch my output frame, (I mean either pulling the screen horizontally or vertically) the two textboxes and the button shows up. Please check my code and

KeyListener is not working in Java

点点圈 提交于 2019-12-12 05:32:11
问题 I want to be able to receive input from the keyboard by the user but I've added everything I thought would allow my program to do this and still it does not work. What am I doing wrong? class KeyInput implements KeyListener { public void keyPressed(KeyEvent e) { System.out.println("keyPressed"); } public void keyReleased(KeyEvent e) { System.out.println("keyReleased"); } public void keyTyped(KeyEvent e) { System.out.println("keyTyped"); } } public GameView() { this.addKeyListener(new KeyInput

Displaying the labels vertically

假装没事ソ 提交于 2019-12-12 05:30:01
问题 Please, I want to display the labels' text vertically. Also I want the column header to be displayed vertically. actually, I tried to use: public static final String LOGO_PATH = "/org/optaplanner/examples/curriculumcourse/swingui/curriculumCourseLogo.png"; private final TimeTablePanel<Room, Period> roomsPanel; private final TimeTablePanel<Teacher, Period> teachersPanel; private final TimeTablePanel<Curriculum, Period> curriculaPanel; public CurriculumCoursePanel() { setLayout(new BorderLayout

Fit all components from JFrame to actual size of window

佐手、 提交于 2019-12-12 05:08:23
问题 I'm using NetBeans. How I can make all components from my window to resize to actual size of the window? Now when my window is 800x600 and I make it larger, size of all components are the same. I would like to change size of my components when I change size of open application window. I tried to search for answer on the internet but I couldn't find good answer to my problem. 回答1: I tried to search for answer on the internet but I couldn't find good answer to my problem. I find that hard to