首页 \ 问答 \ Java在Swing上绘制圆圈和线条(Java draw circle and lines on Swing)

Java在Swing上绘制圆圈和线条(Java draw circle and lines on Swing)

我想在一个更大的圆形表面内画一个随机中心的圆圈。 (我实际上是想在房间里模拟一个人和他的视力!)我需要绘制一条随机线(称为line1),穿过它的中心,它将与表面相交。 line1不一定通过圆形表面的中心。 我还需要绘制两条线,形成60度,面向line1的一侧。 任何人都可以帮助我吗?

我创建了一个我需要绘制的例子。

在此处输入图像描述

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Random;

import javax.swing.JFrame;

public class ShapeTest extends JFrame{
    int width=500;
    int height=500;

     public ShapeTest(){
          setSize(width,height);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setResizable(false);
          setLocationRelativeTo(null);
          setVisible(true);
     }

     public static void main(String a[]){
         new ShapeTest();
     }

     public void paint(Graphics g){
         // Circular Surface
         drawCircleByCenter(g, width/2, height/2, width/2);
         Random r = new Random();
         Point center = new Point();
         center.x=r.nextInt(width/2);
         center.y=r.nextInt(width/2);
         drawCircleByCenter(g, center.x, center.y, width/15);
     }

     void drawCircleByCenter(Graphics g, int x, int y, int radius){
         //g.setColor(Color.LIGHT_GRAY);
         g.drawOval(x-radius, y-radius, 2*radius, 2*radius);
     }
}

I'm trying to draw a circle with a random center inside a big bigger circular surface. (I'm actually trying to simulate a human and his eyesight inside a room!) I need to draw a random line (call it line1) passing through its center which will intersect with the surface. line1 does not necessarily pass the center of circular surface. I also need to draw two lines forming 60 degree, facing on one side of line1. Can anyone help me with that?

I created an example of what I need to draw.

enter image description here

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Point;
import java.util.Random;

import javax.swing.JFrame;

public class ShapeTest extends JFrame{
    int width=500;
    int height=500;

     public ShapeTest(){
          setSize(width,height);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setResizable(false);
          setLocationRelativeTo(null);
          setVisible(true);
     }

     public static void main(String a[]){
         new ShapeTest();
     }

     public void paint(Graphics g){
         // Circular Surface
         drawCircleByCenter(g, width/2, height/2, width/2);
         Random r = new Random();
         Point center = new Point();
         center.x=r.nextInt(width/2);
         center.y=r.nextInt(width/2);
         drawCircleByCenter(g, center.x, center.y, width/15);
     }

     void drawCircleByCenter(Graphics g, int x, int y, int radius){
         //g.setColor(Color.LIGHT_GRAY);
         g.drawOval(x-radius, y-radius, 2*radius, 2*radius);
     }
}

原文:https://stackoverflow.com/questions/22573385
更新时间:2024-03-21 18:03

最满意答案

看起来像日志查看器问题(或某些不那么直观的功能?),如果您在日志表上方的第二个下拉列表中选择“所有日志”(或“活动”,在某些情况下显示),则会发生这种情况。

如果您选择“request_log”,则日志显示OK(即通常的方式):

在此处输入图像描述

查看器界面描述看起来下拉列表被称为“日志选择器”,并且从该描述中看起来它与计算引擎相关并且不应该出现在App Engine日志查看器上:)


Looks like a log viewer problem (or some not so intuitive feature?), happening if you select "All logs" (or "activity", showing in some cases) in the 2nd dropdown list above the logs table.

Logs show OK (i.e. the usual way) if you select "request_log" instead:

enter image description here

From the viewer interface description it appears the dropdown is called "Log Selector" and from this description it appears it is Compute Engine related and shouldn't show up on the App Engine logs viewer :)

相关问答

更多
  • 这是Google Compute Engine的限制。 托管虚拟机使用GCE来为应用程序提供服务。 目前,任何执行出站网络呼叫的虚拟机都需要具有公共外部IP。 我们正在努力解决这个问题,但它仍然是一条出路。 默认情况下,免费试用帐户的默认配额为23个外部IP。 您可以通过上面链接的配额增加请求表单要求增加配额 。 This is a limitation of Google Compute Engine. Managed VMs use GCE under the hood to serve applica ...
  • 很可能您在日志记录期间使用调试级别,但您的logging.properties文件具有INFO级别。 将其更改为DEBUG: # Set the default logging level for all loggers to WARNING .level = DEBUG Most probably you use debug level during logging, but your logging.properties file has INFO level. Change it to DEBUG: ...
  • 这是一个sqlite文件,可以用sqlite3模块读取它。 It's an sqlite file, can just read it with sqlite3 module.
  • 如果问题仅存在于路由中,那么您肯定可以使用带端点的默认模块和前端的模块“网站” 。 那么你的调度文件应该是这样的(python版本,Java应该非常相似): dispatch: - url: "*/_ah/*" module: default - url: "*/*" module: website 调度文件显然使用从上到下的优先级设置路由,因此每个针对端点* / _ ah / *的请求将路由到默认模块,其余请求将在网站模块上进行。 但是,如果您遇到CORS问题,则可以检查处理程序配置中的静态文 ...
  • 你在发出HTTPS请求吗? 官方文档指出SSL证书不支持双通配符域。 Google建议使用HTTPS协议向您的应用发送请求。 Google不会为appspot.com上托管的双通配符域颁发SSL证书。 因此,使用HTTPS时,您必须使用字符串“-dot-”而不是“。” 分隔子域名 所以你需要更换第一个. 使用-dot-来遵循这种模式: https://module-dot-app-id.appspot.com : -dot- 。 在你的情况下api-dot-app-id.appspot.com 。 OK, ...
  • 在.uplugin文件中,查看您的模块名称,然后在testplugin.cpp中查看以下行: IMPLEMENT_MODULE(TestPluginImpl, TestPlugin) 我确定他们需要匹配。 例如: "Modules" : [ { "Name" : "NebulaAudioAnalysisPlugin", "Type" : "Runtime" } ] 我的实现看起来像: IMPLEMENT_M ...
  • 弄清楚了。 我不得不在我的模块中添加一个处理程序。 我补充说: - url: /_ah/start script: colors.handler.app 我的handlers:它工作。 Figured it out. I had to add a handler to my module. I added: - url: /_ah/start script: colors.handler.app to my handlers: and it worked.
  • 看起来像日志查看器问题(或某些不那么直观的功能?),如果您在日志表上方的第二个下拉列表中选择“所有日志”(或“活动”,在某些情况下显示),则会发生这种情况。 如果您选择“request_log”,则日志显示OK(即通常的方式): 从查看器界面描述看起来下拉列表被称为“日志选择器”,并且从该描述中看起来它与计算引擎相关并且不应该出现在App Engine日志查看器上:) Looks like a log viewer problem (or some not so intuitive feature?), h ...
  • 您需要将请求模块(即请求文件夹的内容)放在项目目录中。 只是为了清楚起见,你的app目录应该看起来像 /myapp/app.yaml /myapp/main.py /myapp/requests/packages/ /myapp/requests/__init__.py /myapp/requests/adapters.py etc... 然后在main.py中放入类似的东西 import webapp2 import requests class MainHandler(webapp2.Request ...
  • 当您使用路径进行模块路由时,并不意味着路径映射到模块的根,它只是确定哪个模块有机会处理请求。 除非你的列表模块处理/列表中有代码,否则它将是404。 When you use a path for module routing, it doesn't mean that path maps to the root of the module it just determines which module gets a chance to handle the request. Unless you have ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)