相关疑难解决方法(0)

使用Graphics2D翻转图像

我一直想弄清楚如何翻转图像一段时间,但还没想到.

我使用Graphics2D画一个Image

g2d.drawImage(image, x, y, null)
Run Code Online (Sandbox Code Playgroud)

我只需要一种在水平轴或垂直轴上翻转图像的方法.

如果你想要,你可以看看github上的完整源代码.

java swing image graphics2d

21
推荐指数
2
解决办法
4万
查看次数

JFrame中的绘图窗口

我想使用java.awt/javax.swing在一个更大的窗口内有一个单独的图形窗口(以及一个单独的笛卡尔坐标平面),我画了一张图片来告诉你我的意思.

我不知道如何做到这一点,把一些文献扔给我,我可以阅读,以便更好地理解这将是非常好的,我的问题的解决方案将是非常棒的.

PS.我没有真正尝试过任何东西,因为我不知道该尝试什么.

java layout swing awt

5
推荐指数
1
解决办法
1095
查看次数

在JFrame中使用坐标平面

//我正在尝试学习如何在java中绘制对象.我越来越好了,但是一旦我在屏幕上看到图像,我就无法操作它.我输入的数字对形状的变化没有意义.至少在我看来他们没有.在代数中,如果你在x轴上增加一个数字,它会向右移动,如果你在y轴上增加一个数字,它就会上升.那不是在这里发生的事情.任何人都可以向我解释这是如何工作的?我还是java的新手,所以解释和细节越多越好.我想在夏天花一两个小时来学习java,有时候会有点沮丧.任何帮助是极大的赞赏.

java swing awt jframe coordinates

5
推荐指数
1
解决办法
1万
查看次数

使用AffineTransform将Shape缩放/转换为给定的Rectangle

我正在尝试扩展/翻译java.awt.使用AffineTransform进行形状,以便在定义的边界Rectangle中绘制它.

此外,我想在具有" 缩放 "参数的绘图区域中绘制它.

我尝试了各种AffineTransform连接,但我找不到正确的序列.例如,以下解决方案是错误的:

double zoom=(...);/* current zoom */
Rectangle2D viewRect=(...)/** the rectangle where we want to paint the shape */
Shape shape=(...)/* the original shape that should fit in the rectangle viewRect */
Rectangle2D bounds=shape.getBounds2D();

double ratioW=(viewRect.getWidth()/bounds.getWidth());
double ratioH=(viewRect.getHeight()/bounds.getHeight());


AffineTransform transforms[]=
    {
    AffineTransform.getScaleInstance(zoom, zoom),
    AffineTransform.getTranslateInstance(-bounds.getX(),-bounds.getY()),
    AffineTransform.getTranslateInstance(viewRect.getX(),viewRect.getY()),
    AffineTransform.getScaleInstance(ratioW, ratioH)
    };


AffineTransform tr=new AffineTransform();
for(int i=0;i< transforms.length;++i)
    {
    tr.concatenate(transforms[i]);
    }

Shape shape2=tr.createTransformedShape(shape);
graphics2D.draw(shape2);
Run Code Online (Sandbox Code Playgroud)

关于正确的AffineTransform的任何想法?

非常感谢

皮埃尔

java graphics drawing shapes affinetransform

3
推荐指数
1
解决办法
1万
查看次数

使用Affine Trasform缩放时,JPanel不绘制

我的应用程序布局类似于:自定义JFrame(仅处理gui的创建),其中包含一个标准JPanel,其中包含一个自定义JPanel

在自定义的JPanel(称为MinimapPanel)内部,我更改了paint方法:

    //in a constructor:
    scaledTransform = new AffineTransform(); = new AffineTransform();
    scaledTransform = new AffineTransform();
    scaledTransform.scale(scaleAmount, scaleAmount);
    //...
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    g2d.setTransform(scaledTransform);
    mapDrawer.paintMinimap(g, seatMap, miniViewHandler);//it just calls a bunch of fillRect

    if (viewRect != null) {
        g.setColor(new Color(255, 0, 0));
        int x = viewRect.x;
        int y = viewRect.y;
        g.drawRect(x, y, Math.abs(viewRect.width), Math.abs(viewRect.height));
    }
    g2d.setTransform(plainTransform);
}
Run Code Online (Sandbox Code Playgroud)

如果我不应用trasform,或者缩放比例为1.0(无),则一切正常,但如果缩放,则每次JFrame重新绘制时,MinimapPanel都保持空白。

关于我可能做错了什么的任何想法?

java scaling swing paint affinetransform

3
推荐指数
1
解决办法
603
查看次数

Java Swing中的图形绘制仅绘制点

我目前正在开发一个程序,其中某些随时间演变的数值变量在每次迭代时都会显示其值.这很好用,但现在我想绘制一张图表,显示它们随时间的演变.所以,我查看了一个用于在Swing中绘制图形的代码示例.我的最终代码如下所示:

public class Populus3 extends JPanel
{
    public static void main(String[] args) throws IOException {

        final Populus3 pop = new Populus3();

        JFrame f = new JFrame(); //where I want to plot the graph
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new GraphingData());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);


        frame = new JFrame("Animation Frame"); //where I'm running animation for another element of the program
        frame.add(pop, BorderLayout.CENTER);
        frame.setSize(graphSize, graphSize);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //insert all sort of things

    }


    public void paint(Graphics g) 
    {
        super.paint(g);
        paintCell(g, 1);
        Toolkit.getDefaultToolkit().sync(); // necessary for linux users …
Run Code Online (Sandbox Code Playgroud)

java swing graph

3
推荐指数
2
解决办法
1万
查看次数

使用鼠标和图形缩放

我在JComponent中绘制了一些曲线等,使用了图形G(不是2D).

现在我想使用鼠标滚轮进行放大和缩小.

任何曲目?

我听说过BuferredImage?

java swing awt zoom

3
推荐指数
1
解决办法
1万
查看次数

在JPanel上使用滑块绘制二次公式

所以,我正在尝试制作一个程序,你可以通过滑块输入二次公式(ax ^ 2 + bx + c).然后在调整A,B和C时绘制图形.

问题:

我希望我用超级油漆写的东西和滑块在一个地方.当我运行滑块时,滑块就位.有正确背景的空间我希望我的图表在面板中,但没有实际的图形.

这是我的驱动程序类:

import java.awt.*;
import javax.swing.*;

public class quadraticslider
{

     public static void main (String[] args)
   {
      JFrame frame = new JFrame ("Quadratic Slider");
      frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

      frame.getContentPane().add(new pp109quadraticpanel());

      frame.pack();
      frame.setVisible(true);
   }
}
Run Code Online (Sandbox Code Playgroud)

这是小组类:

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;

public class quadraticpanel extends JPanel
{
   private JPanel controls, graphPanel;
   private JSlider ASlider, BSlider, CSlider;
   private JLabel ALabel, BLabel, CLabel;
   double A, B, C, x,Y;

  //
  //SLIDERS YO
  //
   public quadraticpanel()
   {
      ASlider …
Run Code Online (Sandbox Code Playgroud)

java swing compiler-errors jpanel

2
推荐指数
1
解决办法
3424
查看次数

使用paintComponent在JFrame中镜像对象

我创建了一个类,它是一个“镜像”对象。类构造函数具有镜像坐标和方向。在这个类中也有一个paintComponent方法。我正在尝试在我的框架中使用此类创建一个镜像对象,并自动绘制带有坐标和方向的镜像。有“镜像”类。我可以这样做吗?

import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JComponent;

@SuppressWarnings("serial")
    class Mirror extends JComponent{

        public static int xm, ym;
        public static boolean direction;

        public Mirror(int xmm, int ymm, boolean directionm){

            xm=xmm;
            ym=ymm;
            direction=directionm;;
            repaint();
        }

        public int getX(){
            return xm;
        }

        public int getY(){
            return ym;
        }

        public boolean getDirection(){
            return direction;
        }

        public int getIntDirection(){
            int a;

            if(direction==true){
                a=1;
            }else{
                a=0;
            }

            return a;
        }

        public void setDirection(boolean status){
            direction=status;
        }

        @Override
        public void paintComponent(Graphics g){
            super.paintComponent(g); …
Run Code Online (Sandbox Code Playgroud)

java swing paintcomponent imageicon

0
推荐指数
1
解决办法
295
查看次数