使用 PaintComponent 计算两个矩形的交集

2024-04-07

我正在编写一个程序,允许用户将矩形绘制到JLabel,并显示这些矩形的交集和并集。我已经为该类设置了 GUI,但正在努力寻找一种方法来集成矩形类中的交集和并集方法。我知道这些方法在与 GUI 分开使用时是有效的。

当我尝试运行该程序时,我不断收到IndexOutOfBoundsException并且绘制的矩形将从 GUI 中清除。每个矩形的交点应在屏幕上以不同的颜色显示JLabel。我尝试调试程序,由于某种原因,当我创建两个矩形并将它们存储在我的数组列表中时,正在创建许多具有相同特征的矩形对象。

对于 union 方法,应创建一个新矩形,其中包含内部的所有矩形。

矩形框1:

public class RectangleFrame1 extends JFrame implements ActionListener
{


    JPanel buttonPanel;
    JButton saveImage;
    JButton clearImage;
    JCheckBox intersections;
    JCheckBox union;
    RectangleLabel drawingArea;
    boolean intersect = false;
    boolean uni = false;

    public RectangleFrame1()
    {
        super();
        setTitle("Rectangles");
        setSize(600,600);
        setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        buttonPanel = new JPanel();
        buttonPanel.setBorder(BorderFactory.createLineBorder(Color.black));
        this.add(buttonPanel, BorderLayout.SOUTH);

        intersections = new JCheckBox("Draw Intersections");
        buttonPanel.add(intersections);
        intersections.addActionListener(this);
        intersections.setActionCommand("Intersections");

        union = new JCheckBox("Draw Union");
        buttonPanel.add(union);
        union.addActionListener(this);
        union.setActionCommand("Union");

        saveImage = new JButton("Save Image");
        saveImage.setMargin(new Insets(0,0,0,0));
        buttonPanel.add(saveImage);
        saveImage.addActionListener(this);
        saveImage.setActionCommand("Save Image");

        clearImage = new JButton("Clear Image");
        clearImage.setMargin(new Insets(0,0,0,0));
        buttonPanel.add(clearImage);
        clearImage.addActionListener(this);
        clearImage.setActionCommand("Clear Image");

        drawingArea = new RectangleLabel();
        drawingArea.setBorder(BorderFactory.createLineBorder(Color.blue));
        this.add(drawingArea, BorderLayout.CENTER);
        drawingArea.addMouseListener((MouseListener) drawingArea);
        drawingArea.addMouseMotionListener((MouseMotionListener) drawingArea);

    }

    @Override
    public void actionPerformed(ActionEvent arg0)
    {
        switch(arg0.getActionCommand())
        {
            case "Intersections":
            if(intersections.isSelected())
            {
                intersect = true;
            }
            else
            {
                intersect = false;
            }
            case "Union":
            if(union.isSelected())
            {
                uni = true;
            }
            else
            {
                uni = false;
            }
            case "Clear Image": drawingArea.clearImage();
            case "Save Image": drawingArea.saveImage();
        }

    }

    class RectangleLabel extends JLabel implements MouseListener, MouseMotionListener
    {

        Rectangle rectangle = null;
        int x, y, x2, y2;
        ArrayList<Rectangle> a = new ArrayList();
        int counter;
        public RectangleLabel()
        {
            super();
        }
        @Override
        public void mousePressed(MouseEvent arg0)
        {
            x = arg0.getX();
            y = arg0.getY();

            rectangle = new Rectangle(x, y, 0, 0);
        }

        @Override
        public void mouseDragged(MouseEvent arg0)
        {
            // TODO Auto-generated method stub
            x2 = arg0.getX();
            y2 = arg0.getY();

            if(rectangle.getX() > x2)
            {
                rectangle.setWidth(x-x2);
            }
            if(x2 > rectangle.getX())
            {
                rectangle.setWidth(x2-x);
            }
            if(y > y2)
            {
                rectangle.setHeight(y-y2);
            }
            if(y2 > y)
            {
                rectangle.setHeight(y2-y);
            }

            a.add(rectangle);
            counter++;
            repaint();

        }

        @Override
        public void mouseReleased(MouseEvent arg0)
        {
            repaint();
        }

        @Override
        public void mouseMoved(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            if(rectangle != null)
            {
                for(int i = 0; i < a.size(); i++)
                {
                    float thickness = 2;
                    ((Graphics2D) g).setStroke(new BasicStroke(thickness));
                    g.setColor(Color.BLUE);
                    g.drawRect(a.get(i).getX(), a.get(i).getY(), a.get(i).getWidth(), a.get(i).getHeight());
                    g.setColor(Color.gray);
                    g.fillRect(a.get(i).getX(), a.get(i).getY(), a.get(i).getWidth(), a.get(i).getHeight());
                }
            }

            if(intersect == true && counter > 0)
            {
                for(int h = 0; h < counter-1; h++)
                {
                    for(int j = 1; j < counter; j++)
                    {   if(a.get(h).overlaps(a.get(j)))
                        {
                            Rectangle rect = a.get(h).intersect(a.get(j));
                            g.setColor(Color.RED);
                            g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
                        }
                    }
                }
            }

            if(uni == true && counter > 0)
            {
                for(int h = 0; h < counter - 1; h++)
                {
                    for(int j = 1; j < counter; j++)
                    {
                        Rectangle rect = a.get(h).union(a.get(j));
                        g.setColor(Color.WHITE);
                        g.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());

                    }
                }
            }
        }


        public void saveImage()
        {
            BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D aaaaa = image.createGraphics();
            aaaaa.setBackground(Color.WHITE);
            aaaaa.clearRect(0, 0, this.getWidth(), this.getHeight());
            this.paintAll(aaaaa);
            try
            {
                File output = new File("rectangle.png");
                ImageIO.write(image, "Rectangles", output);
            }
            catch(IOException ie)
            {

            }
        }
        public void clearImage()
        {
            a.clear();
            repaint();
        }

    }

}

长方形:

public class Rectangle
{


    private int x,y,width,height;

    public Rectangle(int x,int y,int width,int height)
    {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    public Rectangle(Rectangle a)
    {
        this.x = a.x;
        this.y = a.y;
        this.width = a.width;
        this.height = a.height;
    }

    public String toString()
    {
        return "Start: ("+x+","+y+"), Width: "+width+", Height: "+height+"\n";
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }

    public int getWidth()
    {
        return width;
    }

    public int getHeight()
    {
        return height;
    }

    public void setX(int x)
    {
        this.x = x;
    }

    public void setY(int y)
    {
        this.y = y;
    }

    public void setWidth(int width)
    {
        this.width = width;
    }

    public void setHeight(int height)
    {
        this.height = height;
    }

    public int area()
    {
        return width*height;
    }

    public boolean overlaps(Rectangle a)
    {
        if ((x>a.x+a.width) || (a.x>x+width) || (y>a.y+a.height) || (a.y>y+height))
        {
            return false;
        }
        return true;
    }

    public Rectangle intersect(Rectangle a)
    {
        if (!overlaps(a))
            return null;

        int left,right,top,bottom;

        if (x<a.x)
            left = a.x;
        else
            left = x;

        if (y<a.y)
            bottom = a.y;
        else
            bottom = y;

        if ((x+width)<(a.x+a.width))
            right = x+width;
        else
            right = a.x+a.width;

        if ((y+height)<(a.y+a.height))
            top = y+height;
        else
            top = a.y+a.height;

        return new Rectangle(left,bottom,right-left,top-bottom);
    }

    public Rectangle union(Rectangle a)
    {
        int left,right,top,bottom;

        if (x<a.x)
            left = x;
        else
            left = a.x;

        if (y<a.y)
            bottom = y;
        else
            bottom = a.y;

        if ((x+width)<(a.x+a.width))
            right = a.x+a.width;
        else
            right = x+width;

        if ((y+height)<(a.y+a.height))
            top = a.y+a.height;
        else
            top = y+height;

        return new Rectangle(left,bottom,right-left,top-bottom);
    }
}

有很多问题...

You're mouseDragged事件处理程序添加相同的Rectangle to the a ArrayList,一次又一次地增加counter价值随之而来。

这不是必需的。您需要做的就是添加Rectangle on the mousePressed事件。什么时候mouseReleased被称为,你可以评估Rectangle检查大小是否大于0x0如果不是,则将其删除(即删除任何Rectangle其尺寸为0x0)

不要依赖counter变量,值很容易与变量的大小不一致a List。相反,依靠a.size反而。

The switch声明在你的ActionListener正在评估匹配的案例,而且还评估其下面的所有以下案例。这是一个特点switch。如果不想评估以下情况,则需要添加break在每个案例的末尾(或者在您想要“中断”处理的任何地方)。

例如,当您单击Draw Intersections,它也在评估Union, Clear Image and Save Image案例...

你可以尝试使用类似...

switch (arg0.getActionCommand()) {
    case "Intersections":
        intersect = intersections.isSelected();
        break;
    case "Union":
        uni = union.isSelected();
        break;
    case "Clear Image":
        drawingArea.clearImage();
        break;
    case "Save Image":
        drawingArea.saveImage();
        break;
}

反而...

绘画代码中的逻辑错误...

还有一个逻辑区域与您的intersect绘制代码,它将一个矩形与其自身进行比较,最终绘制整个矩形。

代替

if (a.get(h).overlaps(a.get(j))) {

您可能会考虑使用

if (!a.get(h).equals(a.get(j)) && a.get(h).overlaps(a.get(j))) {

这也可能发生在你的联合绘画逻辑中,但我并没有真正检查过

对我来说效果很好...

import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class RectangleFrame1 extends JFrame implements ActionListener {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                }

                RectangleFrame1 frame = new RectangleFrame1();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }

    JPanel buttonPanel;
    JButton saveImage;
    JButton clearImage;
    JCheckBox intersections;
    JCheckBox union;
    RectangleLabel drawingArea;
    boolean intersect = false;
    boolean uni = false;

    public RectangleFrame1() {
        super();
        setTitle("Rectangles");
        setSize(600, 600);
//        setResizable(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        buttonPanel = new JPanel();
        buttonPanel.setBorder(BorderFactory.createLineBorder(Color.black));
        this.add(buttonPanel, BorderLayout.SOUTH);

        intersections = new JCheckBox("Draw Intersections");
        buttonPanel.add(intersections);
        intersections.addActionListener(this);
        intersections.setActionCommand("Intersections");

        union = new JCheckBox("Draw Union");
        buttonPanel.add(union);
        union.addActionListener(this);
        union.setActionCommand("Union");

        saveImage = new JButton("Save Image");
        saveImage.setMargin(new Insets(0, 0, 0, 0));
        buttonPanel.add(saveImage);
        saveImage.addActionListener(this);
        saveImage.setActionCommand("Save Image");

        clearImage = new JButton("Clear Image");
        clearImage.setMargin(new Insets(0, 0, 0, 0));
        buttonPanel.add(clearImage);
        clearImage.addActionListener(this);
        clearImage.setActionCommand("Clear Image");

        drawingArea = new RectangleLabel();
        drawingArea.setBorder(BorderFactory.createLineBorder(Color.blue));
        this.add(drawingArea, BorderLayout.CENTER);
        drawingArea.addMouseListener((MouseListener) drawingArea);
        drawingArea.addMouseMotionListener((MouseMotionListener) drawingArea);

    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        switch (arg0.getActionCommand()) {
            case "Intersections":
                intersect = intersections.isSelected();
                break;
            case "Union":
                uni = union.isSelected();
                break;
            case "Clear Image":
                drawingArea.clearImage();
                break;
            case "Save Image":
                drawingArea.saveImage();
                break;
        }
        repaint();
    }

    class RectangleLabel extends JLabel implements MouseListener, MouseMotionListener {

        Rectangle rectangle = null;
        int x, y, x2, y2;
        ArrayList<Rectangle> a = new ArrayList();

        public RectangleLabel() {
            super();
        }

        @Override
        public void mousePressed(MouseEvent arg0) {
            x = arg0.getX();
            y = arg0.getY();

            rectangle = new Rectangle(x, y, 0, 0);
            a.add(rectangle);
        }

        @Override
        public void mouseDragged(MouseEvent arg0) {
            // TODO Auto-generated method stub
            x2 = arg0.getX();
            y2 = arg0.getY();

            if (rectangle.getX() > x2) {
                rectangle.setWidth(x - x2);
            }
            if (x2 > rectangle.getX()) {
                rectangle.setWidth(x2 - x);
            }
            if (y > y2) {
                rectangle.setHeight(y - y2);
            }
            if (y2 > y) {
                rectangle.setHeight(y2 - y);
            }

            repaint();

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {
            rectangle = null;
            repaint();
        }

        @Override
        public void mouseMoved(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseEntered(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseExited(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void mouseClicked(MouseEvent arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            for (Rectangle rect : a) {
                float thickness = 2;
                ((Graphics2D) g).setStroke(new BasicStroke(thickness));
                g.setColor(Color.BLUE);
                g.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
                g.setColor(Color.gray);
                g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
            }

            if (intersect) {
                for (int h = 0; h < a.size() - 1; h++) {
                    for (int j = 1; j < a.size(); j++) {
                        if (!a.get(h).equals(a.get(j)) && a.get(h).overlaps(a.get(j))) {
                            Rectangle rect = a.get(h).intersect(a.get(j));
                            g.setColor(Color.RED);
                            g.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
                        }
                    }
                }
            }

            if (uni) {
                for (int h = 0; h < a.size() - 1; h++) {
                    for (int j = 1; j < a.size(); j++) {
                        if (!a.get(h).equals(a.get(j)) && a.get(h).overlaps(a.get(j))) {
                            Rectangle rect = a.get(h).union(a.get(j));
                            g.setColor(Color.WHITE);
                            g.drawRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());

                        }
                    }
                }
            }
        }

        public void saveImage() {
            BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D aaaaa = image.createGraphics();
            aaaaa.setBackground(Color.WHITE);
            aaaaa.clearRect(0, 0, this.getWidth(), this.getHeight());
            this.paintAll(aaaaa);
            try {
                File output = new File("rectangle.png");
                ImageIO.write(image, "Rectangles", output);
            } catch (IOException ie) {

            }
        }

        public void clearImage() {
            a.clear();
            repaint();
        }

    }

    public class Rectangle {

        private int x, y, width, height;

        public Rectangle(int x, int y, int width, int height) {
            this.x = x;
            this.y = y;
            this.width = width;
            this.height = height;
        }

        public Rectangle(Rectangle a) {
            this.x = a.x;
            this.y = a.y;
            this.width = a.width;
            this.height = a.height;
        }

        public String toString() {
            return "Start: (" + x + "," + y + "), Width: " + width + ", Height: " + height + "\n";
        }

        public int getX() {
            return x;
        }

        public int getY() {
            return y;
        }

        public int getWidth() {
            return width;
        }

        public int getHeight() {
            return height;
        }

        public void setX(int x) {
            this.x = x;
        }

        public void setY(int y) {
            this.y = y;
        }

        public void setWidth(int width) {
            this.width = width;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public int area() {
            return width * height;
        }

        public boolean overlaps(Rectangle a) {
            if ((x > a.x + a.width) || (a.x > x + width) || (y > a.y + a.height) || (a.y > y + height)) {
                return false;
            }
            return true;
        }

        public Rectangle intersect(Rectangle a) {
            if (!overlaps(a)) {
                return null;
            }

            int left, right, top, bottom;

            if (x < a.x) {
                left = a.x;
            } else {
                left = x;
            }

            if (y < a.y) {
                bottom = a.y;
            } else {
                bottom = y;
            }

            if ((x + width) < (a.x + a.width)) {
                right = x + width;
            } else {
                right = a.x + a.width;
            }

            if ((y + height) < (a.y + a.height)) {
                top = y + height;
            } else {
                top = a.y + a.height;
            }

            return new Rectangle(left, bottom, right - left, top - bottom);
        }

        public Rectangle union(Rectangle a) {
            int left, right, top, bottom;

            if (x < a.x) {
                left = x;
            } else {
                left = a.x;
            }

            if (y < a.y) {
                bottom = y;
            } else {
                bottom = a.y;
            }

            if ((x + width) < (a.x + a.width)) {
                right = a.x + a.width;
            } else {
                right = x + width;
            }

            if ((y + height) < (a.y + a.height)) {
                top = a.y + a.height;
            } else {
                top = y + height;
            }

            return new Rectangle(left, bottom, right - left, top - bottom);
        }
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 PaintComponent 计算两个矩形的交集 的相关文章

  • 存根方法时出现 InvalidUseOfMatchersException

    我有这个 TestNG 测试方法代码 InjectMocks private FilmeService filmeService new FilmeServiceImpl Mock private FilmeDAO filmeDao Bef
  • 如何在 Firebase 远程配置中从 JSON 获取值

    我是 Android 应用开发和 Firebase 的新手 我想知道如何获取存储在 Firebase 远程配置中的 JSONArray 文件中的值 String 和 Int 我使用 Firebase Remote Config 的最终目标是
  • Java:在 eclipse 中导出到 .jar 文件

    我正在尝试将 Eclipse 中的程序导出到 jar 文件 在我的项目中 我添加了一些图片和 PDF s 当我导出到 jar 文件时 似乎只有main已编译并导出 我的意愿是如果可能的话将所有内容导出到 jar 文件 因为这样我想将其转换为
  • 如何根据运行的 jar 的结果让我的 ant 任务通过或失败?

    我正在运行 CrossCheck 无浏览器 js 单元测试 作为 ant 脚本的一部分 如果 CrossCheck 测试失败 我希望 ant 报告失败 这是 build xml 中的相关部分
  • 来自十六进制代码的 Apache POI XSSFColor

    我想将单元格的前景色设置为十六进制代码中的给定颜色 例如 当我尝试将其设置为红色时 style setFillForegroundColor new XSSFColor Color decode FF0000 getIndexed 无论我在
  • 是否可以通过编程方式查找 logback 日志文件?

    自动附加日志文件以支持电子邮件会很有用 我可以以编程方式设置路径 如以编程方式设置 Logback Appender 路径 https stackoverflow com questions 3803184 setting logback
  • 使用 Guice 优化注册表

    你好 今天思考了一种优化 有一些疑问 语境 我正在使用 Guice 2 进行 Java 开发 在我的网络应用程序中 我有一个转换器注册表 可以即时转换为某种类型 转换器描述如下 public class StringToBoolean im
  • 生成的序列以 1 开头,而不是注释中设置的 1000

    我想请求一些有关 Hibernate 创建的数据库序列的帮助 我有这个注释 下面的代码 在我的实体类中 以便为合作伙伴表提供单独的序列 我希望序列以 1000 开头 因为我在部署期间使用 import sql 将测试数据插入数据库 并且我希
  • Freemarker 和 Struts 2,有时它计算为序列+扩展哈希

    首先我要说的是 使用 Struts2 Freemarker 真是太棒了 然而有些事情让我发疯 因为我不明白为什么会发生这种情况 我在这里问是因为也许其他人有一个想法可以分享 我有一个动作 有一个属性 说 private String myT
  • java库维护数据库结构

    我的应用程序一直在开发 所以偶尔 当版本升级时 需要创建 更改 删除一些表 修改一些数据等 通常需要执行一些sql代码 是否有一个 Java 库可用于使我的数据库结构保持最新 通过分析类似 db structure version 信息并执
  • 返回 Java 8 中的通用函数接口

    我想写一种函数工厂 它应该是一个函数 以不同的策略作为参数调用一次 它应该返回一个函数 该函数根据参数选择其中一种策略 该参数将由谓词实现 嗯 最好看看condition3为了更好的理解 问题是 它没有编译 我认为因为编译器无法弄清楚函数式
  • 使用布尔值进行冒泡排序以确定数组是否已排序

    我有以下用于冒泡排序的代码 但它根本不排序 如果我删除布尔值那么它工作正常 我知道 由于我的 a 0 小于所有其他元素 因此没有执行交换 任何人都可以帮助我解决这个问题 package com sample public class Bub
  • 是否可以使用 Java Guava 将函数应用于集合?

    我想使用 Guava 将函数应用于集合 地图等 基本上 我需要调整 a 的行和列的大小Table分别使所有行和列的大小相同 执行如下操作 Table
  • Spring-ws:如何从没有“Request”元素的 xsd 创建 Wsdl

    尝试为客户端实现 SOAP Web 服务 我需要一个 wsdl 文件来通过soapUI 测试该服务 但正如您在下面看到的 这个 xsd 没有 Request 和 Response 方法 所有请求和响应都被定义为基本 ServiceProvi
  • 在 Google App-Engine JAVA 中将文本转换为字符串,反之亦然

    如何从字符串转换为文本 java lang String to com google appengine api datastore Text 反之亦然 Check Javadoc http code google com appengin
  • 将 Apache Camel 执行器指标发送到 Prometheus

    我正在尝试转发 添加 Actuator Camel 指标 actuator camelroutes 将交换 交易数量等指标 发送到 Prometheus Actuator 端点 有没有办法让我配置 Camel 将这些指标添加到 Promet
  • 配置“DataSource”以使用 SSL/TLS 加密连接到 Digital Ocean 上的托管 Postgres 服务器

    我正在尝试托管数据库服务 https www digitalocean com products managed databases on 数字海洋网 https en wikipedia org wiki DigitalOcean 创建了
  • 在浏览器刷新中刷新检票面板

    我正在开发一个付费角色系统 一旦用户刷新浏览器 我就需要刷新该页面中可用的统计信息 统计信息应该从数据库中获取并显示 但现在它不能正常工作 因为在页面刷新中 java代码不会被调用 而是使用以前的数据加载缓存的页面 我尝试添加以下代码来修复
  • 洪水填充优化:尝试使用队列

    我正在尝试创建一种填充方法 该方法采用用户指定的初始坐标 检查字符 然后根据需要更改它 这样做之后 它会检查相邻的方块并重复该过程 经过一番研究 我遇到了洪水填充算法并尝试了该算法 它可以工作 但无法满足我对 250 x 250 个字符的数
  • Java EE 目录结构

    我对以下教程有疑问 http www mkyong com jsf2 jsf 2 internationalization example http www mkyong com jsf2 jsf 2 internationalizatio

随机推荐

  • 期间发生内部错误:“更新 Maven 依赖项”

    每当我运行 eclipse 时 我都会收到以下消息 An internal error occurred during Updating Maven Dependencies Lorg codehaus plexus archiver ja
  • 快速向 AVPlayer 添加自定义控件

    我正在尝试创建一个表格视图 以便能够播放视频 我可以使用 AVPlayer 和图层来做到这一点 我想在视频视图底部添加带有滑块的自定义播放和暂停按钮 AVPlayerController 内置有这些控件 我如何在 AVPlayer 中实现这
  • 将报告 (RDLC) 设置为横向打印和 A4

    有没有办法将 RDLC 报告设置为始终横向并始终使用 A4 而无需每次通过打印对话框手动执行此操作 我已经在这个问题上呆了几个小时了 谷歌搜索后什么也没有出现 事实上 有没有办法跳过打印对话框本身 TIA 您当然可以避免打印对话框并直接打印
  • 使用 CursorAdapter 正确实现更改 ListView 数据

    我有一个通过 CursorAdapter 填充的 ListView 我让我的用户能够更改列表中的数据 例如 用户可以将一行标记为未读 数据是消息 假设我的用户将一行标记为未读 正确的实现是否会将数据库中的行标记为已读 然后重新查询游标 正确
  • 动态创建具有不同亮度的颜色

    我有一种颜色 我只在运行时知道 我想使用这种颜色创建两种新颜色 一种非常明亮 一种不明亮 为了澄清一下 假设我的颜色是红色 我想创建 浅红色 颜色和 深红色 颜色的十六进制值 我该怎么做呢 我的代码是使用 GWT 用 Ja va 编写的 将
  • Microsoft JScript 运行时错误:“jQuery”未定义

    我是 ASP MVC 3 菜鸟 正在学习音乐商店教程http www asp net mvc tutorials mvc music store mvc music store part 5 http www asp net mvc tut
  • 将 posixlt 作为新列添加到数据框中

    我正在创建一些随机数 data lt matrix runif 10 0 1 ncol 2 dataframe lt data frame data gt dataframe X1 X2 1 0 7981783 0 13233858 2 0
  • 事务范围的持久性上下文和扩展持久性上下文有什么区别?

    事务范围的持久性上下文和扩展持久性上下文有什么区别 差异在JSR 220 http jcp org aboutJava communityprocess final jsr220 index htmlEnterprise JavaBeans
  • Kubernetes 网络插件

    我已经使用 calico 网络插件安装了 3 个节点的 Kubernetes 集群 出于某种原因 我决定完全删除 kubernetes 并使用不同的网络插件重新安装它 Flannel 一切看起来都很好 直到我尝试部署我的第一个容器 kube
  • 尝试使用 unixODBC/FreeTDS 连接到 PHP 中的 MS SQL Server 时出现 iODBC 错误

    我正在尝试从 Mac 上的 PHP 连接到远程 MS SQL Server 数据库 最终在 Ubuntu 服务器上 使用 FreeTDS 和 unixODBC 但即使我似乎已正确设置所有内容 我仍收到 iODBC 错误 并且我 我不知道如何
  • 在 iOS 3.0 上运行 iOS4 内置的应用程序,为什么一切都很大?

    我的背景和图标都很大 就像放大了 2 倍一样 有什么想法吗 检查应用程序中的图像 应该有两组图像 其中一组为双分辨率且后缀为 2x 如果只有一组并且它们看起来很大 那么开发人员很可能从未打算在不运行 iOS4 的设备上运行该应用程序 这看起
  • Angularjs - ng-model 未定义

    我正在构建一个相当复杂的指令 其中我需要访问模板中特定元素上的 ng model 该元素包含在 ng if 指令中 我有一个plunker http plnkr co edit bQSIZE6gik36UkJkvTM0 p preview下
  • 如何在android中的ble中每5秒更新一次电池电量

    在下面的编码中 我得到了一定百分比的电池电量 但我想调用通知特性 以便每 5 到 10 秒更新一次电池百分比 所以请帮助我 以下是我的设备控制活动 在此我编码如下 private final BroadcastReceiver mGattU
  • 从列表中创建字典

    所以我创建了一个这样的列表 list line strip for line in open file txt r 这是我的清单的一个片段 1 2 2 3 2 3 4 3 1 3 4 5 4 2 1 4 4 8 3 5 2 5 7 15 1
  • Bokeh:鼠标移动或单击的 CustomJS 回调

    我想根据当前鼠标位置更新绘图数据 我的目标是这样的交互幂函数图 http bokeh pydata org en 0 10 0 docs user guide interaction html customjs for widgets 但不
  • ANSI C 函数声明如何改进旧的 Kernighan 和 Ritchie 风格?

    关于 ANSI C 函数声明 这与旧的 K R 风格有何改进 我知道它们之间的区别 我只是想知道使用旧样式会出现什么问题以及新样式是如何改进的 旧式函数声明特别是 不允许对调用进行编译时检查 例如 int func x y char x d
  • 如何使用启用了延迟加载的 Automapper 和 EF4 DbContext 从 ViewModel 更新现有实体

    我正在使用 Automapper 在 Entity 和 ViewModel 对象之间进行映射 双向 该模型使用 EF4 DbContext POCO 并且需要启用 LazyLoading 因此需要启用代理生成 我在尝试从视图模型更新现有实体
  • 获取服务.net core中的appsettings.json值

    I have appsettings json我想在其中声明文件路径的文件 Paths file C file pdf 我想在我的服务中访问这个值 我尝试这样做 public class ValueService IValueService
  • python累加while循环不断重复我做错了什么?

    我不明白我做错了什么 我尝试过使用中断 并尝试设置变量 我在 cengage 上执行此操作 这非常finnicky LeftOrRight py This program calculates the total number of lef
  • 使用 PaintComponent 计算两个矩形的交集

    我正在编写一个程序 允许用户将矩形绘制到JLabel 并显示这些矩形的交集和并集 我已经为该类设置了 GUI 但正在努力寻找一种方法来集成矩形类中的交集和并集方法 我知道这些方法在与 GUI 分开使用时是有效的 当我尝试运行该程序时 我不断