首页 \ 问答 \ drawLine使用AWT(drawLine using AWT)

drawLine使用AWT(drawLine using AWT)

我刚开始使用AWT进行GUI。 框架正在打开,但未显示Line。

帧图像

import java.awt.*;
import java.awt.event.*;

class A extends Frame
{
    public static void main(String args[])
    {
        Frame f= new Frame();
        f.setTitle("New Frame");
        f.setSize(1000,1000);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});

    }
    public void paint(Graphics g)
    {
        g.setColor(Color.blue);
        g.drawLine(60,500,230,5);
    }
}

I just started with GUI using AWT. The frame is opening but the Line is not being displayed.

frame image

import java.awt.*;
import java.awt.event.*;

class A extends Frame
{
    public static void main(String args[])
    {
        Frame f= new Frame();
        f.setTitle("New Frame");
        f.setSize(1000,1000);
        f.setVisible(true);
        f.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent we){System.exit(0);}});

    }
    public void paint(Graphics g)
    {
        g.setColor(Color.blue);
        g.drawLine(60,500,230,5);
    }
}

原文:
更新时间:2022-04-07 07:04

最满意答案

这里有三件事需要考虑:

  1. 数据的性质是什么:设置或文档 - 或者每个的一些?
  2. 是按用户还是按机器安装应用程序?
  3. 设置数据是否应该与用户一起漫游?

有时很难确定数据的性质。 为简单起见,将数据分为两类:设置和文档。 它们通常存储在不同的地方,如The New Old Thing博客中所讨论的

“我的文档”和“应用程序数据”之间最重要的区别是“我的文档”是用户存储文件的位置,而“应用程序数据”是程序存储文件的位置。

如果每台计算机都安装了该应用程序,则“app installer”对用户数据没有任何影响。 (否则,那么用户的数据是什么?)用户使用应用程序(设置)时应由用户创建用户数据,或者用户通过应用程序(文档)创建用户数据。 现在,当用户第一次启动应用程序时,它可以为用户提供管理每用户数据的方法,以便用户可以在卸载应用程序之后或在用户决定不再使用它之后进行清理。

手段可以是应用程序使用UninstallString创建的用户ARP条目,该条目运行复制到用户的AppData文件夹的内容。 或者,它可以是用户执行相同的快捷方式。 或者,如果您需要用户不触发的内容,则用户运行注册表项以启动检测应用程序是否已卸载的实用程序(这可能是一个挑战)。

如果按用户安装应用程序,那么“app install”可以删除应用程序,设置和文档,但应该只删除应用程序。

文档是用户的,但根据应用程序,如果用户无意再次运行应用程序,则文档可能毫无价值。 你应该离开他们或者问他们。

至于设置,正如您所指出的,如果用户将来运行任何版本的应用程序,它们将非常有用。 应用程序应该能够升级或忽略新版本或旧版本的设置。

有关应用数据的更多观看,请参阅此其他New Old Thing 帖子


那么,回答你的问题:

  1. 两者,取决于文件是什么。
  2. 设置:可能(但如果每个用户安装了应用程序,则无法)。 文件:没有。
  3. 通常,应用程序应该创建应用程序数据,但如果您希望用户知道其文档的“所有用户”位置,则会出现例外情况。

只有设计应用程序和安装程序才能产生最佳的用户体验。


There are three things to consider here:

  1. What is the nature of the data: settings or documents—or some of each?
  2. Is the app installed per user or per machine?
  3. Should settings data roam with the user or not?

Sometimes it is hard to determine the nature of the data. For simplicity, divide the data into two categories: settings and documents. They are typically stored in different places as discussed in the The New Old Thing blog

The most important difference between My Documents and Application Data is that My Documents is where users store their files, whereas Application Data is where programs store their files.

If the app is installed per machine then the "app installer" can have nothing to with user data. (If otherwise, then which users' data?) User data should be created by the app when the user uses the app (settings) or by the user through the app (documents). Now, when a user starts the app the first time, it can provide a means for the user to manage the per user data so the user can clean up after the app is uninstalled or after that user decides to not use it anymore.

The means could be a user ARP entry that the app creates with an UninstallString that runs something it copies to the user's AppData folder. Or, it could be a user shortcut to do the same. Or, if you want something the user doesn't trigger, a user Run registry entry to launch a utility that detects if the app has been uninstalled (which could be a challenge).

If the app is installed per user then the "app install" could remove the app, settings and documents but should only remove the app.

Documents are the user's but depending on the app, if a user has no intention of running the app again, the documents might be worthless. You should either leave them or ask.

As for settings, as you point out, they would be useful if the user runs any version of the app in the future. An app should be able to upgrade or ignore settings for a newer or older version.

See this other New Old Thing post for more views on app data.


So, to answer your questions:

  1. Both, depending on what the files are.
  2. Settings: maybe (but can't if the app installed per user). Documents: No.
  3. Usually the app should create app data, but an exception would be if you want users to know of an "all users" location for their documents.

Only designing the app and installer together produce the best user experience.

相关问答

更多
  • 我同意Alex Coplan的一个重要补充。 将所有常量放在一个名为“Constants.h”的文件中(或者你想要的) 编辑: 当我三年前回答这个问题时,我在#define频道里,检查下面的修订。 Constants.h #define kFilterDate @"date" #define kFilterRadius @"radius" #define kFilterSort @"sort" //Global Strings #define kDividingString @" / " //Strin ...
  • 将JSON放入页面的最佳位置在哪里,如果它加载了模态内容? 让我们说我不希望它在需要之前加载; 如果它被应用于第一个模态对话框中的页面并且它被所有其他对话框使用,那么它是宏的,但它也可以仅包含在对话框中并且仅在该对话框打开时使用。 那么JSON在哪里呢? 好吧,将JSON数据保存在网页上很容易。 没有必要将HTML元素视为数据的承载者。 你可以把它放在全局对象window 。 假设你叫这个地方保存你的数据VAULT : // So, we have the JSON come from the se ...
  • 实际上你在这里问了两个问题: 存储和操作数据的位置? 何时以及如何使用$ rootScope(与$ scope相比)? 1)我将参考这篇文章 :每当数据和方法需要重用时,我会编写一个这样的服务。 angular.module('modelDemo').service("myModel", [function() { this.list = [what, ever, items, you, have]; this.property= null; this.setProperty = ...
  • 在应用首次启动时,您可以允许用户根据选择选择他/她的文件夹,然后在将来的访问列表中添加该文件夹。 所以你可以随时访问该文件夹。 请查看下面给出的链接。 如何保存StorageFile以便以后使用? 探索WinRT:Storage.AccessCache Windows.Storage.AccessCache类 On app's first launch, you can allow the user to choose his/her folder as per choice, and then add t ...
  • 嵌入式资源是优选的,因为OS更优化以读取那些而不是独立文件。 但是速度的差异可以忽略不计,所以我建议你试着看看它是否对你有任何影响,尤其是在像诺基亚Lumia 520这样的低端设备上。 Embedded resource is preferable since OS is more optimized to read those rather than standalone files. But the difference in speed may be negligible, so I suggest ...
  • Library / ApplicationSupport将完成我需要的工作......(以防万一其他人需要相同的信息)。 SD Library/ApplicationSupport will do what I need... (just in case someone else needs the same info). SD
  • 试用Google Spreadsheets( Java API参考 )。 您可以上传CSV文件,然后将其自动转换为电子表格,然后您可以通过编程方式查询或编辑它,或者在线操作它 ,然后如果需要将其作为CSV文件导出,可以将其导出 。 Try Google Spreadsheets (Java API Reference). You can upload a CSV which gets automatically converted to a spreadsheet, then you can query o ...
  • 理想情况下,在开发结束时,您可以将此数据填充到Core Data存储中并将其添加到项目中。 首次运行时,您将该应用程序包中的该商店作为用户的Core Data商店进行复制。 这适用于您的情况。 在无法做到这一点的情况下,可以在后台线程上执行导入。 Ideally towards the end of development you would populate this data into a Core Data store and add that to your project. On first ru ...
  • 您可以将表单宏与Laravel Collective Package一起使用 Laravel Collective: https : //github.com/LaravelCollective/html 一个很棒的例子,你可以找到https://github.com/rappasoft/laravel-5-boilerplate 请参阅App \ Providers \ MacroServiceProvider.php I have found a very good solution to this o ...
  • 这里有三件事需要考虑: 数据的性质是什么:设置或文档 - 或者每个的一些? 是按用户还是按机器安装应用程序? 设置数据是否应该与用户一起漫游? 有时很难确定数据的性质。 为简单起见,将数据分为两类:设置和文档。 它们通常存储在不同的地方,如The New Old Thing博客中所讨论的 “我的文档”和“应用程序数据”之间最重要的区别是“我的文档”是用户存储文件的位置,而“应用程序数据”是程序存储文件的位置。 如果每台计算机都安装了该应用程序,则“app installer”对用户数据没有任何影响。 (否则 ...

相关文章

更多

最新问答

更多
  • 您如何使用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)