Hey, this is an English text. I want you to translate it into the Tunisian dialect.…
- User
Hey, this is an English text. I want you to translate it into the Tunisian dialect. Please follow these steps:
- Translate step by step and highlight differences between Tunisian dialect and Modern Standard Arabic.
- Highlight sections you are confident translating into the Tunisian dialect. Translate this text into the Tunisian dialect, focusing on capturing the essence of the language nuances:
Q: Painting and repainting a JPanel with images I wish to paint and repaint a JPanel, which may be rotated 90 degrees with images. The initial painting does not cause any issues. When I try to repaint() the panel it will not do this immediately, but wait for a second repaint(). My second issue is that, when i turn my panel vertical as stated in the below code, it will not repaint at all. I can't see the image red, yellow or green at least, but the image "light" remains. Thank you for taking your time to read this. public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; if(vertical){ g2d.translate(this.getWidth() / 2, this.getHeight() / 2); g2d.rotate(-Math.PI / 2); g2d.translate(-img_light.getWidth(null) / 2, -img_light.getHeight(null) / 2); g2d.drawImage(img_light, 0, 0, this); if(showRed){ g2d.translate(-img_red.getWidth(null) / 2, -img_red.getHeight(null) / 2); g2d.drawImage(img_red, 0, 0, null); } if(showYellow){ g2d.translate(-img_yellow.getWidth(null) / 2, -img_yellow.getHeight(null) / 2); g2d.drawImage(img_yellow, 0, 0, null); } if(showGreen){ g2d.translate(-img_green.getWidth(null) / 2, -img_green.getHeight(null) / 2); g2d.drawImage(img_green, 0, 0, null); } }else{ g2d.drawImage(img_light, 0, 0, this); if(showRed){ g2d.drawImage(img_red, 0, 0, null); } if(showYellow){ g2d.drawImage(img_yellow, 0, 0, null); } if(showGreen){ g2d.drawImage(img_green, 0, 0, null); } } } A: have look at tutorial Graphics2D and two methods about Graphics2d#rotate() then you should be so able code (initial by @CtrAltDelete ???) import java.awt.; import java.awt.event.; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.File; import java.util.; import javax.imageio.ImageIO; import javax.swing.; import javax.swing.Timer; import javax.swing.filechooser.*; public class RotatableImageComponent extends JComponent { private static final long serialVersionUID = 1L; private Image image; private double angle = 0; private MyObservable myObservable; public RotatableImageComponent() { myObservable = new MyObservable(); } public RotatableImageComponent(Image image) { this(); this.image = image; } public Image getImage() { return image; } public void setImage(Image image) { this.image = image; } public double getAngle() { return angle; } public void setAngle(double angle) { if (angle == this.angle) { return; } this.angle = angle; double circle = Math.PI * 2; while (angle < 0) { angle += circle; } while (angle > circle) { angle -= circle; } if (myObservable != null) { myObservable.setChanged(); myObservable.notifyObservers(this); } repaint(); } /** * In the rotation events sent to the listener(s), the second argument * (the value) will be a reference to the RotatableImageComponent. One then * should call getAngle() to get the new value. * @param o */ public void addRotationListener(Observer o) { myObservable.addObserver(o); } public void removeRotationListener(Observer o) { myObservable.deleteObserver(o); } public void rotateClockwise(double rotation) { setAngle(getAngle() + rotation); } public void rotateCounterClockwise(double rotation) { //setAngle(getAngle() - rotation); rotateClockwise(-rotation); } @Override public void paintComponent(Graphics g) { if (image == null) { super.paintComponent(g); return; } Graphics2D g2 = (Graphics2D) g; AffineTransform trans = AffineTransform.getTranslateInstance(getWidth() / 2, getHeight() / 2); trans.rotate(angle); trans.translate(-image.getWidth(null) / 2, -image.getHeight(null) / 2); g2.transform(trans); g2.drawImage(image, 0, 0, null); } @Override public Dimension getPreferredSize() { if (image == null) { return super.getPreferredSize(); } int wid = image.getWidth(null); int ht = image.getHeight(null); int dist = (int) Math.ceil(Math.sqrt(wid * wid + ht * ht)); return new Dimension(dist, dist); } public static class TimedRotation {
- Assistant