小编par*_*cer的帖子

用随机颜色填充对象

我有一个有按钮的代码.按下按钮时,圆圈会随机出现在颜色随机的位置.只能有10个圆圈.

现在我添加了随机颜色功能,问题是在绘制每个圆之后,它的颜色开始变得无用.

我该怎么做才能让颜色不变?

class Panel extends JPanel  {

    private JButton button;
    private Ellipse2D.Double[] circles;
    Integer count;


    public Panel()  {
            setup();
    }

    private void setup()  {
            count=new Integer(0);
            circles=new Ellipse2D.Double[10];
            button=new JButton(count.toString());
            button.addActionListener(new ActionListener() {
               @Override
               public void actionPerformed(ActionEvent e) {
                            Random r=new Random();
                            //position circles with diameter 100 in a way 
                            //that it would fit in a window's size
                            int highX=getWidth()-100;
                            int highY=getHeight()-100;
                            circles[count]=new 
                                     Ellipse2D.Double(r.nextInt(highX), 
                                          r.nextInt(highY), 100, 100);
                            count++;

                            button.setText(count.toString());
                    }
                });

          add(button);
        }


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

java swing

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

亚马逊网络服务 AWS:如何托管​​ Java 应用程序、分配自定义域、自定义域名无法正常工作

我在这里托管了一个站点:http : //testapp-test.us-west-2.elasticbeanstalk.com/someservlet.do

该站点包含一个index.jsp和一个someservlet

https://my.freenom.com机柜中,我尝试:设置名称服务器并将 url 转发设置为http://testapp-test.us-west-2.elasticbeanstalk.com。前者不起作用:我将名称服务器设置为屏幕显示,当尝试访问 codingrecords.tk 时,它只是空白。然而,URL 转发有效,它确实显示了主页,但是当我尝试访问http://codingrecords.tk/someservlet.do 时,它仍然显示index.jsp消息。

我如何解决它?通过指定名称服务器,而不是 url 转发?但后来它也不起作用..

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

java deployment subdomain web-deployment amazon-web-services

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

Javascript:getElementsByClassName:如何只获取父母

我有这样的html:

<div class="item">
    <img class="item-image" src="${item.getImage()}"/>
    <p>${item.getName()}</p>
</div>
Run Code Online (Sandbox Code Playgroud)

和 Javascript:

var classname = document.getElementsByClassName("item");

for (var i = 0; i < classname.length; i++) {
    classname[i].addEventListener('click', (e) => {
        addBorder(e.target);

    });
};

function addBorder(item) {
    if (item.tagName = 'DIV') {
        item.style.border = "3px solid red";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我单击项目时,它会添加一个红色边框。但是,如果单击碰巧触摸图像或段落,则会在它们周围绘制红色边框。我试图通过在里面添加 if 条件来防止它addBorder,但它没有帮助。有没有办法只使父 div 带有红色边框,即使点击发生在里面pimg

在此处输入图片说明

html javascript css

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

JavaFX:如何在达到零时停止时间轴倒数计时器

我有这段代码显示从 10 向下倒计时:

在此处输入图片说明

然而,它在达到零后继续计数为负数。达到零后如何停止?以便在标签上显示的最后一个文本是0.

import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class TestCountdown extends Application {
    private GridPane gridPane;
    private Scene scene;

    private Button button = new Button("Start");
    private CountdownTimer timer = new CountdownTimer();

    @Override
    public void start(Stage applicationStage) {
        gridPane = new GridPane();
        scene = new Scene(gridPane);

        gridPane.add(timer, 0, 1);
        gridPane.add(button, 0, 2);

        timer.setStyle("-fx-font-size: 50;");
        button.setStyle("-fx-font-size: 50;");

        button.setOnAction(actionEvent -> timer.start());

        applicationStage.setScene(scene);
        applicationStage.setFullScreen(true);
        applicationStage.show(); …
Run Code Online (Sandbox Code Playgroud)

java javafx

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

如何使用函数参数:调用特定的getter

我有一个带有名称和品种的狗类。我想根据传递给 printDog 方法的方法参数打印狗的名字或品种。我怎么做?

class Dog  {
  private String name;
  private String breed;

  //constructor

  public String getName()  {
    return name;
  }

  public String getBreed()  {
    return breed;
  }
}
Run Code Online (Sandbox Code Playgroud)
public void printDog(Dog dog, ?)  {
  System.out.println(dog.?);
}
Run Code Online (Sandbox Code Playgroud)
Dog dog = new Dog("Buster", "Shepherd");
printDog(dog, dog::getName);
printDog(dog, dog::getBreed);
Run Code Online (Sandbox Code Playgroud)

java

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

Vue:NavigationDuplicated:避免了到当前位置的冗余导航,但需要重新加载页面

我有这个Hashtag.vue对象:

<template>
  <div   v-on:click="clicked">
  <div
               class="tag rounded-full p-2   ">
    {{text}}</div>
  </div>
</template>


<script>
export default {
  props: {
    text: {
      type: String
    },
    date:  {
      type: String
    },
    link: {
      type: String,

    }
  },
  created()  {
    console.log("this link: " + this.link);
  },
  methods:  {
    clicked()  {

      this.$router.push({
        path: this.getTo
      })
    }
  },
  computed:  {
    getTo: function()  {
      console.log("text: " + this.text);
      console.log("link: " + "hashtag/" + this.text);
      return "/hashtag/" + this.text;
    }
  }
}
</script>
Run Code Online (Sandbox Code Playgroud)

当它被点击时,它需要转到

http://localhost:8080/hashtag/text
Run Code Online (Sandbox Code Playgroud)

它会转到那里并显示带有此主题标签的文章。 …

javascript vue.js vuejs2

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

Java ExecutorService,newVirtualThreadPerTaskExecutor:线程在从扫描器获取输入之前退出

我有这个简单的代码,用于在第一个线程中从用户那里获取名称,将其添加到队列中,并使用第二个线程打印名称:

import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

public class TestThreads {
    private static final Scanner scanner = new Scanner(System.in);
    private static ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor();
    private static LinkedBlockingQueue<String> names = new LinkedBlockingQueue<>();
    
    public static void main(String[] args) {
        executor.submit(() -> {
            try {
                while (true) {
                    String name = getName();
                    names.add(name);
                }
            } catch (Exception e)  {
                e.printStackTrace();
            }
        });

        executor.submit(() -> {
            try {
                while (true) {
                    if (!names.isEmpty())  {
                        String name = names.poll();
                        System.out.println("\n**** The name …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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