awt

Cast jzy3d.canvas to awt.component

ε祈祈猫儿з 提交于 2019-12-04 06:15:04
问题 I need cast the jzy3d canvas to java.awt.component, I want to display the chart in my frame with JCombobox and button but when I want to cast canvas to component, the program was dropped. Thank you for your answers. I have try this and don't help me. Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.jzy3d.plot3d.rendering.canvas.VoidCanvas cannot be cast to java.awt.Component at cz.bia.Launcher.lambda$setComponents$0(Launcher.java:63) at java.awt.Button

drawPolygon keeps drawing lines from starting (mousePressed) location to current (mouseDragged) location

ぐ巨炮叔叔 提交于 2019-12-04 05:37:47
问题 So, I'm trying to dynamically draw a Polygon starting from when I click the mouse until I stop dragging and release. Instead of, for the purpose of this question, a square outline being drawn when I click, drag down, then right-across, then up, then left-across, this is what happens: http://imgur.com/t8ZN3Pp Any suggestions? Notes: model.addPolygon() creates a Polygon with starting points and adds it to an ArrayList called 'polys' model.addPolygonPoint() adds points to this created polygon

Android: The type java.awt.Image cannot be resolved. It is indirectly referenced from required .class files

六眼飞鱼酱① 提交于 2019-12-04 05:23:57
I am using some java projects in my Android project . I gave reference to those projects by adding them in Java Build Path and Project References . After doing this i can access classes of java projects in my android project. but getting this error The type java.awt.Image cannot be resolved. It is indirectly referenced from required .class files what should i do now?? Do i need to add any JRE or something else would help?? Found solution: go to project properties java build pata -> Add library and add JRE System Library and click finish . Now you can use java.awt package :) You can't use

Graphics in repaint draws random lines

南笙酒味 提交于 2019-12-04 05:17:35
问题 So I'm creating a free hand drawing JPanel, that reacts to mouse movements and draws lines. I got it mostly working except for a bug where it'll randomly draw a straight line between lines. That random straight line isn't intentional, what's drawn on the buffered image is supposed to be strictly what the user draws. These random drawn lines are not done by the user and it's confusing. Below is my code, can anyone take a look? The image included gives you a visual representation of what it is

Java - Convert Image to black and white - fails with bright colors

筅森魡賤 提交于 2019-12-04 05:07:25
I'm attempting to convert an image to black and white only (not grey scale). I've used this: BufferedImage blackAndWhiteImage = new BufferedImage( dWidth.intValue(), dHeight.intValue(), BufferedImage.TYPE_BYTE_BINARY); Graphics2D graphics = blackAndWhiteImage.createGraphics(); graphics.drawImage(colourImage, 0, 0, null); return blackAndWhiteImage; Everything fine, until I decided to try out brighter colors, like the Google logo for example: and it came out with this: Then I tried first to pass trough grey scale first using: BufferedImage blackAndWhiteImage2 = new BufferedImage( dWidth.intValue

SwingUtilities.invokeLater takes a Runnable and runs it on the EDT?

蹲街弑〆低调 提交于 2019-12-04 05:05:52
I am confused with the signature of SwingUtilities.invokeLater . It takes a Runnable object. Is it this Runnable object that is handed over to the Event Dispatch Thread? Why can't I directly call createAndShowGUI on the run method of EDT (if it is possible)? I have read articles on SO on how the EDT and invokeLater work, but I am confused with the Runnable object that is passed. SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); And what would happen if I call SwingUtilities.invokeLater again right below the call? SwingUtilities.invokeLater(new Runnable()

close window on button click

我只是一个虾纸丫 提交于 2019-12-04 05:04:53
问题 Hello, I am using Java Swing and I want to close a window on a button click. I don't know using an actionlistener as the best way to do this but currently I am having compilation errors with it so its must be incorrect. Here my code: public class assignment2 { public static void main(String[] args){ MyFrame f = new MyFrame(); //open the inital gui interface f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); //set it visibile } } //this is the initial gui screen, presenting

Why does swing draw simple component twice?

北战南征 提交于 2019-12-04 05:04:34
Here is simple example of drawing an oval. public class SwingPainter extends JFrame{ public SwingPainter() { super("Swing Painter"); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); getContentPane().add(new MySwingComponent()); setSize(200, 200); setVisible(true); } public static void main(String[] args) { new SwingPainter(); } class MySwingComponent extends JComponent { public void paintComponent(Graphics g) { System.out.println("paintComponent"); super.paintComponent(g); g.setColor(Color.red); g.fillOval(10, 10, 50, 50); } @Override protected void paintBorder(Graphics g) { System.out

rotate a picture around it's center

筅森魡賤 提交于 2019-12-04 05:01:39
问题 Is there an easy way to rotate a picture around it's center? I used an AffineTransformOp first. It seems simple and need and finding the right parameters for a matrix should be done in a nice and neat google session. So I thought... My Result is this: public class RotateOp implements BufferedImageOp { private double angle; AffineTransformOp transform; public RotateOp(double angle) { this.angle = angle; double rads = Math.toRadians(angle); double sin = Math.sin(rads); double cos = Math.cos

Difference between KeyBindings and KeyListeners

可紊 提交于 2019-12-04 04:30:04
问题 What is the point of KeyBindings if you could just do: // Imports public void Test { JButton button1; JButton button2; JButton button3; ... Test() { button1 = new JButton(); button1.addKeyListener(this); button2 = new JButton(); button2.addKeyListener(this); button3 = new JButton(); button3.addKeyListener(this); ... } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { Object src = e.getSource(); if (src == button1) { ... } else if