swing

Undo button for drawings in a JFrame

我们两清 提交于 2021-02-18 19:00:54
问题 I am drawing some objects on a JFrame such as circles, rectangles and arcs between them. I was wondering how I can implement an Undo button bearing in mind that the ones I found are targeted at text fields and writing in them. I don't have code to show and I wish to receive advice on how to implement it. Is it possible to 'register' the last event that occurred and then delete it? I have a very simple code about deleting the circles for instance. It works only for them and I know that it is

杨玲 201771010133《面向对象程序设计(java)》第十六周学习总结

ぃ、小莉子 提交于 2021-02-17 22:23:51
《面向对象程序设计( java )》第十六周学习总结 第一部分:理论知识学习部分 1、程序是一段静态的代码,它是应用程序执行的蓝本。进程是程序的一次动态执行,它对应了从代码加载、执行至执行完毕的一个完整过程。操作系统为每个进程分配一段独立的内存空间和系统资源,包括:代码数据以及堆栈等资源。每一个进程的内部数据和状态都是完全独立的。多任务操作系统中,进程切换对CPU资源消耗较大。 2、多线程是进程执行过程中产生的多条执行线索。线程是比进程执行更小的单位。线程不能独立存在,必须存在于进程中,同一进程的各线程间共享进程空间的数据。每个线程有它自身的产生、存在和消亡的过程,是一个动态的概念。多线程意味着一个程序的多行语句可以看上去几乎在同一时间内同时运行。线程创建、销毁和切换的负荷远小于进程,又称为轻量级进程。 3、Java实现多线程有两种途径:创建Thread类的子类;在程序中定义实现Runnable接口的类。 4、用Thread类的子类创建线程:首先需从Thread类派生出一个子类,在该子类中重写run()方法。然后用创建该子类的对象Lefthand left=new Lefthand(); Righthand right=new Righthand();最后用start()方法启动线程 left.start(); right.start(); 5

How to add text to a textArea instead of replacing it

隐身守侯 提交于 2021-02-17 21:38:14
问题 How can I add text to a JTextArea instead of replacing all of it? I know about setText(String) but other than that I'm a bit lost. 回答1: You can use the append method like this: textArea.append(additionalText); 回答2: To insert string at any position you can use the component's Document. public static void main(String[] args) throws BadLocationException { JTextField f = new JTextField("foo bar"); int offset = 7; String str = " baz"; f.getDocument().insertString(offset, str, SimpleAttributeSet

How to add text to a textArea instead of replacing it

巧了我就是萌 提交于 2021-02-17 21:37:17
问题 How can I add text to a JTextArea instead of replacing all of it? I know about setText(String) but other than that I'm a bit lost. 回答1: You can use the append method like this: textArea.append(additionalText); 回答2: To insert string at any position you can use the component's Document. public static void main(String[] args) throws BadLocationException { JTextField f = new JTextField("foo bar"); int offset = 7; String str = " baz"; f.getDocument().insertString(offset, str, SimpleAttributeSet

How to check if and which mouse button is pressed in Swing

守給你的承諾、 提交于 2021-02-17 05:47:46
问题 How can I check if currently any mouse button is pressed and if so, which one it is? The thing is that I need to use this kind of information in MouseListener.mouseEntered() . I checked MouseEvent but I could not find the method which would help me. The getButton() method seems to only return value if there has been change in buttons' state. Is there a way to find this out without manually keeping track of this somehow vie MouseListener.mousePressed()/mouseReleased() methods. 回答1: How can I

JPanel not changing on JFrame

徘徊边缘 提交于 2021-02-17 05:43:25
问题 The idea is to have one "global" JFrame which I can then add/remove JPanels as needed to make a smooth flowing application. Currently, when I try changing from the first JPanel to the second, the second won't display. My code is below: Handler (class to run the app): package com.example.Startup; import com.example.Global.Global_Frame; public class Handler { public Handler() { gf = new Global_Frame(); gf.getAccNum(); gf.setVisible(true); } public static void main(String[] args) { new Handler()

JPanel not changing on JFrame

痴心易碎 提交于 2021-02-17 05:41:02
问题 The idea is to have one "global" JFrame which I can then add/remove JPanels as needed to make a smooth flowing application. Currently, when I try changing from the first JPanel to the second, the second won't display. My code is below: Handler (class to run the app): package com.example.Startup; import com.example.Global.Global_Frame; public class Handler { public Handler() { gf = new Global_Frame(); gf.getAccNum(); gf.setVisible(true); } public static void main(String[] args) { new Handler()

How to run a Swing application on a web page?

强颜欢笑 提交于 2021-02-17 05:40:09
问题 I have created a Swing application in Netbeans that is basically a chat system (between multiple clients and server using socket programming). Now I wanted to run this application on a webpage. Is this possible without changing any code? 回答1: Now I wanted to run this application on a webpage. Is this possible without changing any code? No. It would have to be a JApplet to be embedded in a web page, and applets have been effectively killed off. See Java Plugin support deprecated and Moving to

Using a Timer in Swing to display a picture for 5 seconds

时光毁灭记忆、已成空白 提交于 2021-02-17 05:19:45
问题 I am trying to make a login picture for my application using Timer . The idea is, when the user opens the application, he will see a picture for 5 seconds, then the application will start. I tried, as you can see in the method shoutoff() : /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package login; import java.awt.event.ActionEvent; import java.awt.event

Java Swing GUI updating/changing from method - freezing in loop

梦想与她 提交于 2021-02-16 21:19:09
问题 basically, I have this code which was initially working with console i/o now I have to connect it to UI . It may be completely wrong, I've tried multiple things although it still ends up with freezing the GUI. I've tried to redirect console I/O to GUI scrollpane, but the GUI freezes anyway. Probably it has to do something with threads, but I have limited knowledge on it so I need the deeper explanation how to implement it in this current situation. This is the button on GUI class containing