jframe

201771010126 王燕《面向对象程序设计(Java)》第九周学习总结

风格不统一 提交于 2021-02-01 05:51:30
实验九 异常、断言与日志 实验时间 201 8-10-25 1 、实验目的与要求 (1) 掌握java异常处理技术; 异常积极处理方法:使用try子句捕获异常 异常小计处理方法:抛出throw异常类 (2) 了解断言的用法; 断言:是一种错误处理机制,是在程序的开发和测试阶段使用的工具。 断言(assert)是JDK1.4中引入的一个新的关键字,语法如下: assert 条件 或者assert 条件:表达式 这两个形式都会对“条件”进行判断, “条件”是一个布尔表达式。如果判断结果为假(false)则抛出AssertionError。在第二种形式中,“表达式”会传进AssertionError的构造函数中并转成一个消息字符串。 “表达式”部分的唯一目的就是生成一个消息字符串。 AssertionError对象并不存储表达式的值,因此你不可能在以后获取它。 断言仅仅应该在测试阶段用来定位程序内部错误。 可以将断言语句作为方法的前置条件或后置条件来添加,也可以将其置于任何方法内,或放在if…else块和switch块中。assert 关键字的唯一限制在于它必须位于可执行块中。 对一个方法调用是否使用断言,应先看看该方法的文档。如果文档指明在某种情况下会抛出异常,那么对这种情况不需使用断言;如果文档指明一个限制条件,但没有说明违反该条件会抛出异常,此时就可以使用断言。 (3)

Is there a way to hide the title bar, but keep the buttons in JFrame

蓝咒 提交于 2021-01-29 16:27:13
问题 I was wondering if I could hide the title bar in Java Swing, but keep the maximize, minimize, and close buttons. I've tried adding frame.setUndecorated(true); but it removes the maximize, minimize, and close buttons completely. Here is my code: public Display(String title, int width, int height) { Display.width = width; Display.height = height; Display.absWidth = width; Display.absHeight = height; Display.d = new Dimension(width, height); setProperties(); image = new BufferedImage(width,

How to show image in JFrame

别等时光非礼了梦想. 提交于 2021-01-29 07:19:23
问题 Okay, this is likely to be flagged as a repeated question, but please hear me out first. I have looked all over the internet and have tried various ways to show an image in a JFrame , but nothing has worked for me. Is there any simple, foolproof! way to show an image in JFrame ? Because if it's not foolproof, I'm sure to mess it up :/ 回答1: You can try this out, I have commented what I have done and where to try and make it understandable and included a bit about resizing from this post. See

How to check how many characters will fit in a title in a `JFrame`?

こ雲淡風輕ζ 提交于 2021-01-29 06:11:22
问题 I have a JFrame as a top-level window of a Swing application used for editing files. I want to display a filename as editors usually do. My current code is a simple: frame.setTitle(appTitle + " - " + filePath) Including a full path is desired, as I often open the file with the same filename from different directories. Sometimes however, when the window is narrow and the path long, the path will not fit into the space available and it is shown shortened, ending with ellipsis: In such situation

How to add any Component in the JFrame TitleBar

橙三吉。 提交于 2021-01-29 02:40:38
问题 How to add any Component like a JButton on the JFrame TitleBar in java swing. 回答1: I assume by "title bar" you think of the header with the window menu button, document or program title and buttons for (typical) maximize, minimize, close. The window borders are drawn by the operating system (whatever part, e.g. with XServer it would be a window manager most of the time) - usually. And this is what the user wants - usually. Then this part of the window is outside the reach of Swing, you need

How to add any Component in the JFrame TitleBar

狂风中的少年 提交于 2021-01-29 02:39:24
问题 How to add any Component like a JButton on the JFrame TitleBar in java swing. 回答1: I assume by "title bar" you think of the header with the window menu button, document or program title and buttons for (typical) maximize, minimize, close. The window borders are drawn by the operating system (whatever part, e.g. with XServer it would be a window manager most of the time) - usually. And this is what the user wants - usually. Then this part of the window is outside the reach of Swing, you need

Cannot set maximum size for JFrame (under Windows)

好久不见. 提交于 2021-01-27 20:52:52
问题 I am trying to limit the maximum size of a JFrame . However, this works only under Linux . Under Windows, the JFrame is freely resized. The code is pretty simple: public class TestMaxSize extends javax.swing.JFrame { public TestMaxSize() { setSize(new java.awt.Dimension(400, 400)); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMaximizedBounds(new java.awt.Rectangle(0, 0, 400, 400)); setMaximumSize(new java.awt.Dimension(400, 400)); setVisible(true); } public static

Creating a JFrame from another JFrames constructor

≯℡__Kan透↙ 提交于 2021-01-27 20:02:39
问题 I have 3 objects that extend JFrame let's call them FrameA FrameB FrameC . FrameA is my main application window. From FrameA 's constructor if the application is not registered I create FrameB and FrameC . They are just popup's that indicate trial period. 2 times out of 10 application freezes and never shows the B anc C frame and frame A becomes unresponsive. I was wondering if there is a side effect of creating frames in this fashion? 回答1: That's because you are not letting FrameA finish it

How to Run application in background when close the JFrame?

泄露秘密 提交于 2021-01-27 05:28:35
问题 I used a system tray in my java application. I want to disappear the GUI and run the application in background , but system tray must remain available when user click on close button of JFrame. 回答1: I want to disappear the GUI and run the application in background, but system tray must remain available when user click on close button of JFrame. set proper JFrames method for DefaultCloseOperation, JFrame.setDefaultCloseOperation(HIDE_ON_CLOSE) , by default implemented in API Sets the operation

Java Game Development: Graphics

こ雲淡風輕ζ 提交于 2021-01-21 10:03:13
问题 i'm new here. Hope you will be able to help. Problem: Problem with displaying Animation on JFrame. Seems I miss/don't understand enough how Java's graphics works. Global idea: Lets say I want make a game/movie/clip. For this I need this (not)simple animation get working. An example for this question: I got class Screen, which has the screen stuff- Declaration of the JFrame, setting up its configuration(size, close operation, etc) and then creating the objects of class Box, to be showed on the