如何在 JPanel 中为矩形设置动画?

2023-12-12

我想为我的项目学习一些有关 JAVA 的技巧。

我想从左到右、从右到左对我的矩形进行动画处理,但我无法对球动画应用相同的功能。

另外,如何以 y 坐标边框在不同的 x 方向上启动我的球?

非常感谢您的建议和帮助。

enter image description here

我的代码:

import javax.swing.Timer;
import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MultipleBall extends JApplet {
public MultipleBall() {
    add(new BallControl());
}

class BallControl extends JPanel {
    private BallPanel ballPanel = new BallPanel();
    private JButton Suspend = new JButton("Suspend");
    private JButton Resume = new JButton("Resume");
    private JButton Add = new JButton("+1");
    private JButton Subtract = new JButton("-1");
    private JScrollBar Delay = new JScrollBar();

    public BallControl() {
        // Group buttons in a panel
        JPanel panel = new JPanel();
        panel.add(Suspend);
        panel.add(Resume);
        panel.add(Add);
        panel.add(Subtract);

        // Add ball and buttons to the panel
        ballPanel.setBorder(new javax.swing.border.LineBorder(Color.red));
        Delay.setOrientation(JScrollBar.HORIZONTAL);
        ballPanel.setDelay(Delay.getMaximum());
        setLayout(new BorderLayout());
        add(Delay, BorderLayout.NORTH);
        add(ballPanel, BorderLayout.CENTER);
        add(panel, BorderLayout.SOUTH);

        // Register listeners
        Suspend.addActionListener(new Listener());
        Resume.addActionListener(new Listener());
        Add.addActionListener(new Listener());
        Subtract.addActionListener(new Listener());
        Delay.addAdjustmentListener(new AdjustmentListener() {

            public void adjustmentValueChanged(AdjustmentEvent e) {
                ballPanel.setDelay(Delay.getMaximum() - e.getValue());
            }
        });
    }

    class Listener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == Suspend)
                ballPanel.suspend();
            else if (e.getSource() == Resume)
                ballPanel.resume();
            else if (e.getSource() == Add)
                ballPanel.add();
            else if (e.getSource() == Subtract)
                ballPanel.subtract();
        }
    }
}

class BallPanel extends JPanel {
    private int delay = 30;
    private ArrayList<Ball> list = new ArrayList<Ball>();

    // Create a timer with the initial delay
    protected Timer timer = new Timer(delay, new ActionListener() {
        /** Handle the action event */
        public void actionPerformed(ActionEvent e) {
            repaint();
        }
    });

    public BallPanel() {
        timer.start();
    }

    public void add() {
        list.add(new Ball());
    }

    public void subtract() {
        if (list.size() > 0)
            list.remove(list.size() - 1); // Remove the last ball
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawRect(185, 279, 50, 15);
        g.setColor(Color.RED);
        g.fillRect(185, 279, 50, 15);

        for (int i = 0; i < list.size(); i++) {
            Ball ball = (Ball) list.get(i); // Get a ball
            g.setColor(ball.color); // Set ball color

            // Check boundaries
            if (ball.x < 0 || ball.x > getWidth())
                ball.dx = -ball.dx;

            if (ball.y < 0 || ball.y > getHeight())
                ball.dy = -ball.dy;

            // Adjust ball position
            ball.x += ball.dx;
            // ball.y += ball.dy;
            g.fillOval(ball.x - ball.radius, ball.y - ball.radius,
                    ball.radius * 2, ball.radius * 2);
        }
    }

    public void suspend() {
        timer.stop();
    }

    public void resume() {
        timer.start();
    }

    public void setDelay(int delay) {
        this.delay = delay;
        timer.setDelay(delay);
    }
}

class Ball {
    int x = 20;
    int y = 20; // Current ball position
    int dx = 2; // Increment on ball's x-coordinate
    int dy = 2; // Increment on ball's y-coordinate
    int radius = 15; // Ball radius
    Color color = new Color((int) (Math.random() * 256),
            (int) (Math.random() * 256), (int) (Math.random() * 256));
}

/** Main method */
public static void main(String[] args) {
    JFrame frame = new JFrame();
    JApplet applet = new MultipleBallApp();
    frame.add(applet);
    frame.setTitle("MultipleBallApp");
    frame.setLocationRelativeTo(null); // Center the frame
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);
    frame.setLocationRelativeTo(null); // Center the frame
    frame.setVisible(true);
}
}

无法对球动画应用相同的功能

这可能是你的第一个错误。事实上,这正是您应该尝试做的。这个想法是,您应该尝试设计一种方法,通过绘制/动画的内容是抽象的,因此无论您想要绘制什么形状,您都可以将其应用到相同的基本动画过程中......

例如,你可以从某种开始interface它描述了动画实体的基本属性......

public interface AnimatedShape {
    public void update(Rectangle bounds);
    public void paint(JComponent parent, Graphics2D g2d);
}

这表示动画实体可以更新(移动)和绘制。按照惯例(而且因为我很懒),我喜欢创建一个abstract实现最常见方面的实现......

public abstract class AbstractAnimatedShape implements AnimatedShape {

    private Rectangle bounds;
    private int dx, dy;

    public AbstractAnimatedShape() {
    }

    public void setBounds(Rectangle bounds) {
        this.bounds = bounds;
    }

    public Rectangle getBounds() {
        return bounds;
    }

    public int getDx() {
        return dx;
    }

    public int getDy() {
        return dy;
    }

    public void setDx(int dx) {
        this.dx = dx;
    }

    public void setDy(int dy) {
        this.dy = dy;
    }

    @Override
    public void update(Rectangle parentBounds) {
        Rectangle bounds = getBounds();
        int dx = getDx();
        int dy = getDy();
        bounds.x += dx;
        bounds.y += dy;
        if (bounds.x  < parentBounds.x) {
            bounds.x = parentBounds.x;
            setDx(dx *= -1);
        } else if (bounds.x + bounds.width > parentBounds.x + parentBounds.width) {
            bounds.x = parentBounds.x + (parentBounds.width - bounds.width);
            setDx(dx *= -1);
        }
        if (bounds.y < parentBounds.y) {
            bounds.y = parentBounds.y;
            setDy(dy *= -1);
        } else if (bounds.y + bounds.height > parentBounds.y + parentBounds.height) {
            bounds.y = parentBounds.y + (parentBounds.height - bounds.height);
            setDy(dy *= -1);
        }
    }
}

然后开始创建实现......

public class AnimatedBall extends AbstractAnimatedShape {

    private Color color;

    public AnimatedBall(int x, int y, int radius, Color color) {
        setBounds(new Rectangle(x, y, radius * 2, radius * 2));
        this.color = color;
        setDx(Math.random() > 0.5 ? 2 : -2);
        setDy(Math.random() > 0.5 ? 2 : -2);
    }

    public Color getColor() {
        return color;
    }

    @Override
    public void paint(JComponent parent, Graphics2D g2d) {
        Rectangle bounds = getBounds();
        g2d.setColor(getColor());
        g2d.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
    }
}

通过这种方式,您可以自定义实体的动画和绘制方式,但实体的每个实例的基本逻辑是相同的......

但这有什么意义呢...

基本上,它允许我们做的是产生所有动画对象的“虚拟”概念并简化管理,例如......

而不是使用“紧密”耦合List,我们可以使用一对松散的List反而...

private ArrayList<AnimatedShape> list = new ArrayList<AnimatedShape>();

然后当我们想要更新实体时,我们只需要迭代List并要求实体更新...

protected Timer timer = new Timer(delay, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        for (AnimatedShape ball : list) {
            ball.update(getBounds());
        }
        repaint();
    }
});

当它们需要被涂漆时......

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;
    for (AnimatedShape ball : list) {
        ball.paint(this, g2d);
    }
}

因为BallPane不关心它实际上是什么类型的实体,而只关心它是一种类型AnimatedShape...让生活更轻松...

现在,我的实现AnimatedBall已经随机化了球的每个实例的方向,但是您也可以使用以下内容随机化添加球时的起始位置......

public void add() {
    int radius = 15;
    // Randomised position
    int x = (int)(Math.random() * (getWidth() - (radius * 2))) + radius;
    int y = (int)(Math.random() * (getHeight() - (radius * 2))) + radius;
    Color color = new Color((int) (Math.random() * 256),
                    (int) (Math.random() * 256), (int) (Math.random() * 256));

    AnimatedBall ball = new AnimatedBall(x, y, radius, color);

    list.add(ball);
}

但这如何帮助您添加矩形呢?

您现在需要创建一个AnimatedRectangle延伸自AbstractAnimatedShape并实现了所需的方法并将其实例添加到List of AnimatedShape是在BallPane.

如果您不希望在同一列表中管理矩形,您可以创建另一个列表并单独管理它(它创建两个附加方法,update(List<AnimatedShape>) and paint(List<AnimatedShape>, Graphics2D)传递每个单独的列表以减少重复的代码,但这就是我)...

您可以通过覆盖来限制矩形的垂直移动setDy方法并忽略任何更改,例如

Example

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class MultipleBall {

    public MultipleBall() {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    ex.printStackTrace();
                }

                JFrame frame = new JFrame("MultipleBallApp");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.add(new BallControl());
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    public class BallControl extends JPanel {

        private BallPanel ballPanel = new BallPanel();
        private JButton Suspend = new JButton("Suspend");
        private JButton Resume = new JButton("Resume");
        private JButton Add = new JButton("+1");
        private JButton Subtract = new JButton("-1");
        private JScrollBar Delay = new JScrollBar();

        public BallControl() {
            // Group buttons in a panel
            JPanel panel = new JPanel();
            panel.add(Suspend);
            panel.add(Resume);
            panel.add(Add);
            panel.add(Subtract);

            // Add ball and buttons to the panel
            ballPanel.setBorder(new javax.swing.border.LineBorder(Color.red));
            Delay.setOrientation(JScrollBar.HORIZONTAL);
            ballPanel.setDelay(Delay.getMaximum());
            setLayout(new BorderLayout());
            add(Delay, BorderLayout.NORTH);
            add(ballPanel, BorderLayout.CENTER);
            add(panel, BorderLayout.SOUTH);

            // Register listeners
            Suspend.addActionListener(new Listener());
            Resume.addActionListener(new Listener());
            Add.addActionListener(new Listener());
            Subtract.addActionListener(new Listener());
            Delay.addAdjustmentListener(new AdjustmentListener() {

                public void adjustmentValueChanged(AdjustmentEvent e) {
                    ballPanel.setDelay(Delay.getMaximum() - e.getValue());
                }
            });
        }

        class Listener implements ActionListener {

            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == Suspend) {
                    ballPanel.suspend();
                } else if (e.getSource() == Resume) {
                    ballPanel.resume();
                } else if (e.getSource() == Add) {
                    ballPanel.add();
                } else if (e.getSource() == Subtract) {
                    ballPanel.subtract();
                }
            }
        }
    }

    class BallPanel extends JPanel {

        private int delay = 30;
        private ArrayList<AnimatedShape> list = new ArrayList<AnimatedShape>();
        private AnimatedRectange rectangle;

        public BallPanel() {
            this.rectangle = new AnimatedRectange(-25, 200, 50, 25, Color.RED);

            timer.start();
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(400, 400);
        }

        // Create a timer with the initial delay
        protected Timer timer = new Timer(delay, new ActionListener() {
            /**
             * Handle the action event
             */
            @Override
            public void actionPerformed(ActionEvent e) {
                for (AnimatedShape ball : list) {
                    ball.update(getBounds());
                }
                rectangle.update(getBounds());
                repaint();
            }
        });

        public void add() {
            int radius = 15;
            // Randomised position
            int x = (int) (Math.random() * (getWidth() - (radius * 2))) + radius;
            int y = (int) (Math.random() * (getHeight() - (radius * 2))) + radius;
            Color color = new Color((int) (Math.random() * 256),
                            (int) (Math.random() * 256), (int) (Math.random() * 256));

            AnimatedBall ball = new AnimatedBall(x, y, radius, color);

            list.add(ball);
        }

        public void subtract() {
            if (list.size() > 0) {
                list.remove(list.size() - 1); // Remove the last ball
            }
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);

            Graphics2D g2d = (Graphics2D) g;
            for (AnimatedShape ball : list) {
                ball.paint(this, g2d);
            }
            rectangle.paint(this, g2d);
        }

        public void suspend() {
            timer.stop();
        }

        public void resume() {
            timer.start();
        }

        public void setDelay(int delay) {
            this.delay = delay;
            timer.setDelay(delay);
        }
    }

    public interface AnimatedShape {

        public void update(Rectangle bounds);

        public void paint(JComponent parent, Graphics2D g2d);
    }

    public abstract class AbstractAnimatedShape implements AnimatedShape {

        private Rectangle bounds;
        private int dx, dy;

        public AbstractAnimatedShape() {
        }

        public void setBounds(Rectangle bounds) {
            this.bounds = bounds;
        }

        public Rectangle getBounds() {
            return bounds;
        }

        public int getDx() {
            return dx;
        }

        public int getDy() {
            return dy;
        }

        public void setDx(int dx) {
            this.dx = dx;
        }

        public void setDy(int dy) {
            this.dy = dy;
        }

        @Override
        public void update(Rectangle parentBounds) {
            Rectangle bounds = getBounds();
            int dx = getDx();
            int dy = getDy();
            bounds.x += dx;
            bounds.y += dy;
            if (bounds.x  < parentBounds.x) {
                bounds.x = parentBounds.x;
                setDx(dx *= -1);
            } else if (bounds.x + bounds.width > parentBounds.x + parentBounds.width) {
                bounds.x = parentBounds.x + (parentBounds.width - bounds.width);
                setDx(dx *= -1);
            }
            if (bounds.y < parentBounds.y) {
                bounds.y = parentBounds.y;
                setDy(dy *= -1);
            } else if (bounds.y + bounds.height > parentBounds.y + parentBounds.height) {
                bounds.y = parentBounds.y + (parentBounds.height - bounds.height);
                setDy(dy *= -1);
            }
        }
    }

    public class AnimatedBall extends AbstractAnimatedShape {

        private Color color;

        public AnimatedBall(int x, int y, int radius, Color color) {
            setBounds(new Rectangle(x, y, radius * 2, radius * 2));
            this.color = color;
            setDx(Math.random() > 0.5 ? 2 : -2);
            setDy(Math.random() > 0.5 ? 2 : -2);
        }

        public Color getColor() {
            return color;
        }

        @Override
        public void paint(JComponent parent, Graphics2D g2d) {
            Rectangle bounds = getBounds();
            g2d.setColor(getColor());
            g2d.fillOval(bounds.x, bounds.y, bounds.width, bounds.height);
        }
    }

    public class AnimatedRectange extends AbstractAnimatedShape {

        private Color color;

        public AnimatedRectange(int x, int y, int width, int height, Color color) {
            setBounds(new Rectangle(x, y, width, height));
            this.color = color;
            setDx(2);
        }

        // Don't want to adjust the vertical speed
        @Override
        public void setDy(int dy) {
        }

        @Override
        public void paint(JComponent parent, Graphics2D g2d) {
            Rectangle bounds = getBounds();
            g2d.setColor(color);
            g2d.fill(bounds);
        }

    }

    /**
     * Main method
     */
    public static void main(String[] args) {
        new MultipleBall();
    }
}

修正案

  • 你真的应该避免添加JApplet to a JFrame,一个小程序有一个规定的生命周期和管理流程,而你却忽略了。最好只专注于使用BallControlpanel 作为核心 UI 元素,然后将其添加到您想要的顶级容器中
  • 您可能会找到一个JSlider比盗版还多JScrollBar更不用说,它在不同平台上看起来会更好,大多数用户都了解滑块的用途......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 JPanel 中为矩形设置动画? 的相关文章

  • “_加载小部件时出现问题”消息

    加载小部件时 如果找不到资源或其他内容 则会显示 加载小部件时出现问题 就这样 惊人的 此消息保留在主屏幕上 甚至没有说明加载时遇到问题的小部件 我通过反复试验弄清楚了这一点 但我想知道发生这种情况时是否有任何地方可以找到错误消息 Andr
  • 对话框上的 EditText 不返回任何文本

    我太累了 找不到错误 我没有发现任何错误 但我没有从 editText 收到任何文本 请看下面的代码 活动密码 xml
  • 如何在 JSP 中导入类?

    我是一个完全的JSP初学者 我正在尝试使用java util List在 JSP 页面中 我需要做什么才能使用除以下类之外的类java lang 使用以下导入语句进行导入java util List 顺便说一句 要导入多个类 请使用以下格式
  • 内存一致性 - Java 中的happens-before关系[重复]

    这个问题在这里已经有答案了 在阅读有关内存一致性错误的 Java 文档时 我发现与创建 发生 之前 关系的两个操作相关的点 当语句调用时Thread start 每个具有 与该语句发生之前的关系也有一个 与 new 执行的每个语句之间发生的
  • 如何让spring为JdbcMetadataStore创建相应的schema?

    我想使用此处描述的 jdbc 元数据存储 https docs spring io spring integration docs 5 2 0 BUILD SNAPSHOT reference html jdbc html jdbc met
  • 如何在android中设置多个闹钟,在这种情况下最后一个闹钟会覆盖以前的闹钟

    我正在开发一个Android应用程序 用户可以在其中设置提醒时间 但我在以下代码中遇到一个问题 即最后一个警报会覆盖之前的所有警报 MainActivity java public void setreminders DatabaseHan
  • 如何将 android.net.Uri 转换为 java.net.URL? [复制]

    这个问题在这里已经有答案了 有没有办法从Uri to URL 我正在使用的库需要这个 它only接受一个URL但我需要在我的设备上使用图像 如果该方案的Uri is http or https new URL uri toString 应该
  • 将表值参数与 SQL Server JDBC 结合使用

    任何人都可以提供一些有关如何将表值参数 TVP 与 SQL Server JDBC 一起使用的指导吗 我使用的是微软提供的6 0版本的SQL Server驱动程序 我已经查看了官方文档 https msdn microsoft com en
  • 隐式超级构造函数 Person() 未定义。必须显式调用另一个构造函数?

    我正在开发一个项目 但收到错误 隐式超级构造函数 Person 未定义 必须显式调用另一个构造函数 我不太明白它 这是我的人物课程 public class Person public Person String name double D
  • 列表应该如何转换为具体的实现?

    假设我正在使用一个我不知道源代码的库 它有一个返回列表的方法 如下所示 public List
  • RSA OAEP、Golang 加密、Java 解密 -BadPaddingException:解密错误

    我正在尝试解密使用 RSA OAEP 在 Golang 中加密的字符串 但出现 BadPaddingException 解密错误 很难弄清楚我错过了什么 这是Golang加密方法 func encryptString rootPEM io
  • 如何将 Jfreechart(饼图)添加到 netbeans 的面板中

    我正在使用 netbeans gui 编辑器 并且正在尝试添加一个本身位于内部框架中的 Jfreechart 并且这个内部框架我想将其添加到面板中 正如您在此图中看到的那样 抱歉 我无法直接发布图像 因为我新手 http www flick
  • Cloudfoundry:如何组合两个运行时

    cloundfoundry 有没有办法结合两个运行时环境 我正在将 NodeJS 应用程序部署到 IBM Bluemix 现在 我还希望能够执行独立的 jar 文件 但应用程序失败 APP 0 bin sh 1 java not found
  • Android Studio 将音乐文件读取为文本文件,如何恢复它?

    gameAlert mp3是我的声音文件 运行应用程序时 它询问我该文件不与任何文件类型关联 请定义关联 我选择TextFile错误地 现在我的音乐文件被读取为文本文件 我如何将其转换回music file protected void o
  • 如何配置 WebService 返回 ArrayList 而不是 Array?

    我有一个在 jax ws 上实现的 java Web 服务 此 Web 服务返回用户的通用列表 它运行得很好 Stateless name AdminToolSessionEJB RemoteBinding jndiBinding Admi
  • 无法捕获 Spring Batch 的 ItemWriter 中的异常

    我正在编写一个 Spring Batch 流程来将数据集从一个系统迁移到另一个系统 在这种情况下 这就像使用RowMapper实现在传递给查询之前从查询构建对象ItemWriter The ItemWriter称为save我的 DAO 上的
  • JVM:是否可以操作帧堆栈?

    假设我需要执行N同一线程中的任务 这些任务有时可能需要来自外部存储的一些值 我事先不知道哪个任务可能需要这样的值以及何时 获取速度要快得多M价值观是一次性的而不是相同的M值在M查询外部存储 注意我不能指望任务本身进行合作 它们只不过是 ja
  • Java:拆箱整数时出现空指针异常?

    此代码导致空指针异常 我不知道为什么 private void setSiblings PhylogenyTree node Color color throws InvalidCellNumberException PhylogenyTr
  • 挂钩 Eclipse 构建过程吗?

    我希望在 Eclipse 中按下构建按钮时能够运行一个简单的 Java 程序 目前 当我单击 构建 时 它会运行一些 JRebel 日志记录代码 我有一个程序可以解析 JRebel 日志文件并将统计信息存储在数据库中 是否可以编写一个插件或
  • Hibernate 和可序列化实体

    有谁知道是否有一个框架能够从实体类中剥离 Hibernate 集合以使它们可序列化 我查看了 BeanLib 但它似乎只进行实体的深层复制 而不允许我为实体类中的集合类型指定实现映射 BeanLib 目前不适用于 Hibernate 3 5

随机推荐

  • 如果属性名称以 new 开头,应用程序将崩溃

    在我的项目中 我使用 coredata 其中一个实体有一个名为newTotal 在其对应的 NSManagedObject 类中 属性声明如下 property nonatomic strong NSString newTotal 如果我在
  • Yii2 如何从 url 中删除站点/索引和页面参数

    我在默认页面上使用分页 即在 yii2 中的站点 索引上 所以链接器为分页生成的 URL 看起来像这样 domain com site index page 1 我想删除站点 索引和页面参数 使其如下所示 domain com 1 我尝试在
  • WPF 网格水平对齐不起作用。尺寸不变

    我有一个堆栈 堆栈内有一个网格 当我调整窗口大小时 我需要增加堆栈和网格大小 我将 Stack 和 Grid Horizo ntalAlignment 设置为 拉伸 堆栈工作正常 但当我调整窗口大小时 网格大小不会增加 这是我的代码
  • TensorFlow 索引无效(越界)

    您好 我目前正在尝试使用自己的图像数据运行 TensorFlow 但是当我尝试运行这些函数时它崩溃了 它来自 mnist py def loss fn logits labels batch size tf size labels labe
  • opengl:如何避免纹理缩放

    我该如何申请重复无论应用的顶点数据如何 纹理始终保持其原始比例 纹理中的 1 个像素 屏幕上的 1 个像素 我意识到这不是最常见的任务 但是是否可以轻松设置 opengl 来执行此操作 或者我是否需要对尊重其原始外观的顶点数据应用某种掩码
  • java.lang.NullPointerException:尝试在空对象引用上调用虚拟方法以选择 sqlite

    我是安卓世界的新手 我的编码有问题 这只是一个小错误 我不知道它不起作用 即使我改变了其他方法 但错误仍然是相同的错误 这里的错误发生在logcat java lang NullPointerException Attempt to inv
  • 使用 DOM 选项定位 DataTables 元素

    我无法正确定位l长度变化和f分别过滤我的右上角和左下角的输入DT datatable输出在shiny使用dom选项 代码 library shiny library DT set seed 2282018 company lt data f
  • Firebase - 限制特定用户的文件访问权限

    我正在尝试使用 Firebase 实现以下行为 用户使用 Firebase 身份验证登录 用户将文件上传到 Firebase 存储 用户输入不同用户的电子邮件地址 该用户帐户可能已经存在 如果没有 收件人会收到一封电子邮件 提示他们注册 上
  • 在不使用 LINQ 或委托的情况下对 C# 列表 <> 进行排序

    我有一个对象列表 每个对象在 3D 空间中都有一个位置 我需要按到任意点的距离对这个列表进行排序 目前我正在这样做 attachedEffectors attachedEffectors OrderBy x gt Mathf Pow x t
  • 使用 Cypher 从 Neo4j 图中提取子图

    假设我在 Neo4j 中有一个包含 5 个节点的集合 使得集合中的每个节点都连接到集合中的至少一个其他节点 我想从 Neo4j 中提取由节点集合及其交互形成的子图 目前 我正在使用一种非常原始的方法 该方法涉及尝试找到系统中每个节点与其他每
  • 在列表视图中选择 edittexts 文本。怎么办呢?我不知道

    我有一个 ListView 每行都有一个 EditText 正在工作 我需要在单击编辑文本时选择此文本以写入数字 而无需删除或移动光标 首先使用 selectAllonfocus 有效 但是 滚动列表视图后 EditText 变得疯狂并且选
  • 如何安全地处理自定义编写的 PowerShell cmdlet 中的密码?

    假设我有一个自定义 PowerShell Cmdlet 用于导出数据并使用密码对其进行加密 Cmdlet VerbsData Export SampleData public class ExportSampleData PSCmdlet
  • React Native DateTimePicker 的日期格式?

    我正在使用 React Native DateTimePicker https github com react native datetimepicker datetimepicker The onChange事件有时间戳 但我不明白它的
  • 我想在 flutter 中访问我的系统铃声

    有什么办法可以得到所有的铃声手机使用的flutter 并将所选铃声设置为我的应用程序的默认铃声 提前致谢 我设法使用本机代码完成它 首先 您将在 Flutter 端创建这些东西 here where your ringtones will
  • nuxtjs 在点击元素时添加和删除类

    我是 vue 和 nuxt 的新手 这是我需要更新的代码
  • 在win7-64位中通过mingw使用boost.python编译一些代码

    我决定让我的程序兼容windows环境 但是我在windows上的编程经验很少 有一些错误需要帮助 环境 操作系统 win7 64位 IDE 代码块12 11 python Python 2 7 3 Windows X86 64 安装程序
  • googleapi:错误 403:需要“compute.organizations.enableXpnHost”权限

    我已在组织级别为我的用户授予我的管理员用户和服务帐户用户 计算共享 VPC 管理员 角色 但我似乎无法启用请求的权限 我还授予了拥有 namidalab dev networks 项目的文件夹级别的角色 在 IAM 和管理控制台 UI 中选
  • 获取单个 NSDateComponents 的 2 个日期之间的确切差异

    如何获得两个值之间的精确差异 以十进制表示 NSDate Eg 2016 年 1 月 15 日 to 2017 年 7 月 15 日 1 5年 我可以使用类似的东西 NSCalendar currentCalendar components
  • 在 awk 中对块内的行进行排序

    我有一个很长的文件 其中包含依赖项列表 它们的版本以及依赖项所属的服务 该文件按块排序和分隔 这是我引用的文件文件的片段 foo bar baz json jar 2 2 2 compile service ServiceTwo foo b
  • 如何在 JPanel 中为矩形设置动画?

    我想为我的项目学习一些有关 JAVA 的技巧 我想从左到右 从右到左对我的矩形进行动画处理 但我无法对球动画应用相同的功能 另外 如何以 y 坐标边框在不同的 x 方向上启动我的球 非常感谢您的建议和帮助 我的代码 import javax