swing

Java 五子棋小游戏

旧城冷巷雨未停 提交于 2021-02-03 01:09:31
package Day8_06; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; /** * * @author sky * */ public class Game { /** * 控件属性 */ private JFrame frame; // 五子棋游戏的窗口框架 private GameMap map; //

java swing 加载自定义的字体

偶尔善良 提交于 2021-02-02 10:31:49
在实际开发中, 我们需要把字体的名字和字体做一一对应的映射关系, 然后需要通过可配置的方式加载自定义的字体. 所以就有了这个需求, 我们来实现. 首先我们定义一个自定义加载子类的工具类: import java.awt.Font; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.Properties; /** * 字体工具类, 获取需要的字体 */ public class FontUtil { /** * 所有字体配置 */ private static Map<String, String> fontNameMap = new HashMap<String, String>(); /** * 默认字体的大小 */ private static final float defaultFontSize = 20f; static { //加载配置文件 Properties properties = new

201871010123-吴丽丽 《面向对象程序设计(Java)》第八周学习总结

前提是你 提交于 2021-02-01 11:16:28
201871010123-吴丽丽《面向对象程序设计(Java)》第八周学习总结 项目 内容 这个作业属于哪个课程 http://www.cnblogs.com/nwnu-daizh/ 这个作业要求在哪里 https://www.cnblogs.com/nwnu-daizh/p/11703678.html 作业的学习目标 掌握接口定义方法; 掌握实现接口类的定义要求; 掌握实现了接口类的使用要求; 理解程序回调设计模式; 掌握Comparator接口用法; 掌握对象浅层拷贝与深层拷贝方法; 掌握Lambda表达式语法; 了解内部类的用途及语法要求。 第一部分:理论部分 第六章 接口、lambda表达式与内部类 6.1.1接口 1) Java为了克服单继承的缺点,Java使用了接口,一个类可以实现一个或多个接口。 2) 在Java程序设计语言中,接口不是类,而是对类的一组需求描述,由常量和一组抽象方法组成。 3) 接口中不包括变量和有具体实现的方法。 4) 只要类实现了接口,则该类要遵从接口描述的统一格式进行定义,并且可以在任何需要该接口的地方使用这个类的对象. 5)声明方式: public interface 接口名 { …… } 接口体中包含常量定义和方法定义,接口中只进行方法的声明, 不提供方法的实现 。 6)类似建立类的继承关系, 接口也可以扩展 。

java之异常处理

99封情书 提交于 2021-02-01 08:51:40
AboutException的测试: 1 package test; 2 import javax.swing.* ; 3 4 class AboutException { 5 public static void main(String[] a) 6 { 7 @SuppressWarnings("unused" ) 8 int i=1, j=0 , k; 9 // System.out.println("第一次直接对两个整数进行除法运算结果:"); 10 // k=i/j; 11 12 13 try 14 { 15 System.out.println("第五次测试finally语句在没有报错的前提下以及提前退出语句下是否会被执行:" ); 16 // System.out.println("第二次将两个整数放在try{}catch{}函数中进行除法运算结果:"); 17 k = i/j; // Causes division-by-zero exception 18 // throw new Exception("Hello.Exception!"); 19 // System.out.println("第三次测试finally语句在没有报错的情况下是否会被执行:"); 20 21 } 22 23 24 25 catch (Exception e) 26 { 27 28

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)

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

二次信任 提交于 2021-02-01 05:50:57
实验六 接口的定义与使用 实验时间 201 8 - 10 - 18 1 、实验目的与要求 (1) 掌握接口 定义方法 JAVA中通过interface关键字定义接口; 接口中只能定义public static final(也可以在定义时不写,系统是默认的)修饰的变量以及抽象方法 接口中定义的变量必须有初始值 (2) 掌握 实现接口类的定义要求; 接口体中包含常量定义和方法定义,接口中只进行方法的声明,不提供方法的实现;且接口中的任何方法都自动是 public,字段也总是public static final的。 (3) 掌握实现了接口类的使用要求; 接口不能构造接口对象,但可以声明接口变量以指向一个实现了该接口的类的对象。 可以用 instanceof来检查对象是否实现了某个接口。 通常接口的名字以 able或ible结尾; 可以使用 extends来继承接口的常量和抽象方法,扩展形成新的接口; 接口中的所有常量必须是 public static final,方法必须是public abstract,这是系统默认的,不管你在定义接口时,写不写修饰符都是一样的。 在类声明时用 implements关键字声明使用一个或多个接口 一个类使用了某个接口,那么这个类必须实现该接口的所有方法,即为这些方法提供方法体。 一个类可以实现多个接口,接口间应该用逗号分隔开。 若实现接口的类不是抽象类

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

烂漫一生 提交于 2021-01-29 22:43:24
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Not all of my JButtons are showing up after I add a dozen of them. What am I doing wrong?

北城余情 提交于 2021-01-29 22:40:49
问题 I want to add 52 buttons in a JPanel. All with ActionListeners. When I reach a certain amount (13) and run the program, not all of the buttons show up. For example I've added 15 buttons and only 9 or 12 of them show up. Sometimes all of them, but not every time. Here's the code for two of the JButtons: JButton button_one=new JButton(); button_one.setPreferredSize(new Dimension(100,150)); mainpanel.add(button_one); button_one.addActionListener(new ActionListener(){ @Override public void

Java Swing: Making a growing circle by mouse click on JPanel

你说的曾经没有我的故事 提交于 2021-01-29 22:39:32
问题 I'm a beginner in Java and this time I'm trying to learn more by finding code examples and editing them, for example from this website. I have a JFrame and each time it (or more precise the JPanel in it) is clicked on, a circle is drawn which will grow/expand outwards like a water ripple. Each circle starts with a certain radius and will be removed or redrawn when reaching a bigger radius (I chose radius "r" from 10 to 200). I have two programs for this which almost work but are missing

Java Swing: Making a growing circle by mouse click on JPanel

我的未来我决定 提交于 2021-01-29 22:26:05
问题 I'm a beginner in Java and this time I'm trying to learn more by finding code examples and editing them, for example from this website. I have a JFrame and each time it (or more precise the JPanel in it) is clicked on, a circle is drawn which will grow/expand outwards like a water ripple. Each circle starts with a certain radius and will be removed or redrawn when reaching a bigger radius (I chose radius "r" from 10 to 200). I have two programs for this which almost work but are missing