awt

Make a BufferedImage use less RAM?

假如想象 提交于 2019-11-28 23:37:33
问题 I have java program that reads a jpegfile from the harddrive and uses it as the background image for various other things. The image itself is stored in a BufferImage object like so: BufferedImage background background = ImageIO.read(file) This works great - the problem is that the BufferedImage object itself is enormous. For example, a 215k jpeg file becomes a BufferedImag e object that's 4 megs and change. The app in question can have some fairly large background images loaded, but whereas

Apple Retina Display Support in Java JDK 1.7 for AWT / Swing

风格不统一 提交于 2019-11-28 21:13:36
I just became aware that AWT / Swing under Java JDK 1.7 (as of JDK 7u15) does not support Retina displays on Apple Macbook Pros. Netbeans, for example, is nearly unbearable to use for more than a few minutes running on a Retina display and using JDK 1.7. This has been somewhat addressed in a StackExchange question here , and quoting one specific post: Apple's Java 6 JRE will support HiDPI, however it is not currently supported by Oracle's Java 7 JRE. It also doesn't work under the latest dev builds of Java 8. Swing and JavaFX apps are blurry on a Retinia MacBook. This is why IntelliJ still

Why is my line not drawing?

青春壹個敷衍的年華 提交于 2019-11-28 14:50:23
So I have defined a mouseEventlistener and mousemotionListener to define points as so. protected Point elementPosition = null; public Point endPoint = null; public Axis tempAxis; public Graphics g; class MouseButtonHandler extends MouseAdapter { public void mousePressed(MouseEvent e) { if(e.getModifiers()==InputEvent.BUTTON1_MASK) { elementPosition =new Point(e.getX(), e.getY()) ; if(addType==YLABEL) { YDialog ydia = new YDialog(anApp); ydia.setVisible(true); value =(double) ydia.getValue(); ydia.dispose(); } } } public void mouseReleased(MouseEvent e) { } } class MouseMoveHandler extends

How to add to this round button metal background in java?

谁说我不能喝 提交于 2019-11-28 14:42:13
How to give this button background to be as jbutton i want to give this button metal color or grediant color how to make that? import java.awt.*; import java.awt.event.*; RoundButton - a class that produces a lightweight button. Lightweight components can have "transparent" areas, meaning that you can see the background of the container behind these areas. @SuppressWarnings("serial") public class RoundButton extends Component { ActionListener actionListener; // Post action events to listeners String label; // The Button's text protected boolean pressed = false; // true if the button is

KeyListener not working

假如想象 提交于 2019-11-28 14:41:18
public class KL implements KeyListener { public static void main(String[] args) { final JPopupMenu popup = new JPopupMenu(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(300, 200); frame.setVisible(true); } @Override public void keyPressed(KeyEvent arg0) { System.out.println(arg0.getKeyChar()); } @Override public void keyReleased(KeyEvent e) { System.out.println(e.getKeyChar()); } @Override public void keyTyped(KeyEvent e) { System.out.println(e.getKeyChar()); } } That's my class, it's probably something really stupid on my part, but my KeyListener here is not working.

Im not sure how to get the data from my text field

送分小仙女□ 提交于 2019-11-28 14:40:01
I want to get the data from my textfield and set it to int h. and have that change the size of the rectangle im drawing, but im not sure how to go get the data from the textfield, I tired using e.getsource in actionperfomred but it cannot find my textfield. My code is below: import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; import javax.swing.*; import java.net.*; import java.sql.*; import java.lang.Object; import java.awt.Graphics; import java.awt.Graphics2D; /** * This class demonstrates how to load an Image from an external file *

How to implement an infinite image loop?

对着背影说爱祢 提交于 2019-11-28 14:38:00
I am currently working on a 2D shooter with moving background. The background is just a simple image. I want to implement that the image is moving endless from top to bottom. I thought about determining the part of the image that is at the bottom outside the visible part of the frame and paint it on the top again. @Override public void paint(Graphics go) { Graphics2D g = (Graphics2D) go; g.fillRect(0, 0, this.getWidth(), this.getHeight()); g.drawImage(this.imgBackground, 0, this.yBackground, this); } yBackground is the coordinate where the upper left corner of the image is drawn. It is altered

Add an actionListener to a JButton from another class

◇◆丶佛笑我妖孽 提交于 2019-11-28 14:32:46
so I have two classes testPanel and testFrame. All the buttons are in the testPanel class. I want to add ActionListeners to the Jbuttons in the testFrame class. How do I go about doing this? testPanel: public class testPanel extends JPanel{ JLabel codeLbl = new JLabel("Code"); JLabel titleLbl = new JLabel("Title"); JLabel priceLbl = new JLabel("Price"); JTextField codeTxt = new JTextField(20); JTextField titleTxt = new JTextField(20); JTextField priceTxt = new JTextField(20); JButton addBtn = new JButton("Add"); JButton updateBtn = new JButton("Update"); JButton delBtn = new JButton("Delete");

How contents are made translucent in a JPanel?

我怕爱的太早我们不能终老 提交于 2019-11-28 14:23:36
I am confused regarding the display of components in a JPanel. Suppose if I create a custom JPanel with translucency of 0.8f as follows :- JPanel panel=new JPanel(){ @Override public void paint(Graphics g) { super.paint(g); BufferedImage img=(BufferedImage)createImage(getWidth(),getHeight()); Graphics2D g2=(Graphics2D) g.create(); g2.setComposite(AlphaComposite.SrcOver.derive(0.8f)); g2.drawImage(img,0,0,null); } @Override public Dimension getPreferredSize() { return new Dimension(300,300); } }; Now I set it as the contentPane of the frame. frame.setContentPane(panel); Now I add some buttons

How to set present screensize in Java Swing?

老子叫甜甜 提交于 2019-11-28 14:20:10
I have working with swing API for the first time to get the screen resolution for my win application. How to set present screensize in Java Swing? The question depends. Do you want the full screen size or the usable screen size (minus things like the taskbar and the dock)? Do you want the default screen or a specific screen? Full Screen Size, any device... First you need to grab a reference to the current GraphicsEnvironment ... GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); Then you can grab a list of the GraphicsDevice s available on the system... GraphicsDevice