我想从我在单独的类 (Paintball) 中创建的方法 (paint) 绘制图形对象。我希望它仅在我用鼠标左键单击时才在图片框中绘制,并且我希望将我拍摄的点存储在列表中。当我尝试下面的代码时,它不会射击。下面是彩弹射击类。
{
private List<Point> myClick;
public Paintball()
{
myClick = new List<Point>();
}
public void add(Point location)
{
myClick.Add(location);
}
public void paint(Graphics g, Point point)
{
g.FillEllipse(Brushes.Blue, point.X, point.Y, 20, 20);
}
}
Run Code Online (Sandbox Code Playgroud)
}
这是下面的表格1。
namespace AmazingPaintball
{
public partial class Form1 : Form
{
Random positionX = new Random();
Random positionY = new Random();
Target einstein;
int count;
List<Point> ballList = new List<Point>();
Paintball gun;
public Form1()
{
InitializeComponent();
Point point = new Point(positionX.Next(0, …Run Code Online (Sandbox Code Playgroud) 我刚刚安装android studio来制作我的第一个应用程序,但是当我创建一个测试项目时,GUI没有出现并说
渲染问题此版本的渲染库比您的Android Studio版本更新.请更新Android Studio(详细信息)
详情如下.
org.jetbrains.android.uipreview.RenderingException: This version of the rendering library is more recent than your version of Android Studio. Please update Android Studio
at org.jetbrains.android.uipreview.LayoutLibraryLoader.load(LayoutLibraryLoader.java:90)
at org.jetbrains.android.sdk.AndroidTargetData.getLayoutLibrary(AndroidTargetData.java:159)
at com.android.tools.idea.rendering.RenderService.createTask(RenderService.java:164)
at com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel$6.run(AndroidDesignerEditorPanel.java:475)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
at com.intellij.util.ui.update.MergingUpdateQueue$2.run(MergingUpdateQueue.java:254)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:269)
at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:227)
at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:217)
at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:238)
at com.intellij.util.Alarm$Request$1.run(Alarm.java:351)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
请让我知道如何解决问题.
错误消息是:
Error 1 A field initializer cannot reference the non-static field, method, or property 'AmazingPaintball.Form1.thePoint'
Run Code Online (Sandbox Code Playgroud)
这是构造函数:
namespace AmazingPaintball
{
class Paintball
{
public Point startPoint;
public Paintball(Point myPoint)
{
startPoint = myPoint;
}
Run Code Online (Sandbox Code Playgroud)
这是导致错误的代码:
Point thePoint = new Point(50, 50);
Paintball gun = new Paintball(thePoint);
Run Code Online (Sandbox Code Playgroud)