awt

Trying to read Scroll Lock status using JAVA

浪尽此生 提交于 2020-06-26 08:42:28
问题 I have the below lines of code using which i am trying to read status of scroll lock. I get the status of scroll lock when my program starts. However i am willing to get the status realtime. Please guide on the below package assignment; import java.awt.Toolkit; import java.awt.event.KeyEvent; import org.omg.PortableServer.THREAD_POLICY_ID; public class ScrollLockOnOff { public static void main(String[] args) throws InterruptedException { while(true) { Thread.sleep(1000); Toolkit toolkit

How can I add a button to paintComponent panel in java?

孤者浪人 提交于 2020-06-23 18:36:13
问题 The app is an option menu which shows a drawing depending on which button the user presses. I have a container panel with a CardLayout which manages the other panels. I want to show the drawing in my paintComponent Panel, but I also want a button at the bottom of the screen so the user can go back to the main menu. I tried adding it like this but the button didn't appear: CardLayout c1 = new CardLayoutl; JPanel cont1 = new JPanel(); cont1.setLayout(c1); JPanel panel1 = new JPanel(); panel1

java.awt.Rectangle#intersects(Rectangle r) ugly implementation?

我与影子孤独终老i 提交于 2020-06-17 09:45:08
问题 The following is intersects(Rectangle r) method from awt Rectangle source code. I add some comments starting with //* related to my question: Since the code verifies that rw (for example) is positive then rw rw+rx must be bigger than rx . If that is the case rw < rx is always false, so why is it checked ? /** * Determines whether or not this {@code Rectangle} and the specified * {@code Rectangle} intersect. Two rectangles intersect if * their intersection is nonempty. * * @param r the

wrong parent for CardLayout in java

孤街浪徒 提交于 2020-05-30 11:27:13
问题 I want to change cards in my CardLayout (which contains labels) for every choice in my combo box. So when I select Item2 in the combo box it should show the second card but it returns error instead. Inside the method initComponents() I successfully showed the first card using cardLayout.show(imagePanel, "1"); but when I tried to do the same inside private void comboMenuActionPerformed() , it returns the error "IllegalArgumentException: wrong parent for CardLayout". Why is this happening?

Insert data into JTable from JTextField where JTableHeader is null

自古美人都是妖i 提交于 2020-05-16 19:11:41
问题 I am developing small desktop application in java and using the Netbeans IDE . I want read data from JTextField and insert it in the JTable character by character. But issue is that JTableHeader is not available(means that header null). Suggest me some way to resolve this problem. 回答1: But issue is that JTableHeader is not available The table header is a separate component and is only created when you add the table to a JScrollPane. So instead of using code like: panel.add( table ); The logic

Insert data into JTable from JTextField where JTableHeader is null

为君一笑 提交于 2020-05-16 19:11:23
问题 I am developing small desktop application in java and using the Netbeans IDE . I want read data from JTextField and insert it in the JTable character by character. But issue is that JTableHeader is not available(means that header null). Suggest me some way to resolve this problem. 回答1: But issue is that JTableHeader is not available The table header is a separate component and is only created when you add the table to a JScrollPane. So instead of using code like: panel.add( table ); The logic

Circle not showing up in JPanel

五迷三道 提交于 2020-05-09 07:53:44
问题 So I'm trying to draw circles inside of the inner panel. I have a class, paintTimeUnit that creates the circle inside the panel given an xy coordinate pair but whenever I create a new paintTimeUnit object and add it to the panel it doesn't seem to be showing up. public class paintTimeUnit extends JPanel { private static final long serialVersionUID = 1L; private int value; private int xlocation; private int ylocation; public paintTimeUnit(int x, int y) { value = 0; xlocation = x; ylocation = y

201571030135/201571030137《小学四则运算练习软件》结对项目报告

感情迁移 提交于 2020-05-08 05:04:55
任务1源码在Github的仓库主页链接地址: https://github.com/zhanghh2018/201571030135-201571030137 一、需求分析。 1)由计算机从题库文件中随机选择20道加减乘除混合算式,用户输入算式答案,程序检查答案是否正确,每道题正确计5分,错误不计分,20道题测试结束后给出测试总分; 2)题库文件可采用实验二的方式自动生成,也可以手工编辑生成。 3)程序为用户提供三种进阶四则运算练习功能选择:百以内整数算式(必做)、带括号算式、真分数算式练习; 4)程序允许用户进行多轮测试,提供用户多轮测试分数柱状图,示例如下: 5)程序记录用户答题结果,当程序退出再启动的时候,可为用户显示最后一次测试的结果,并询问用户可否进行新一轮的测试; 6)测试有计时功能,测试时动态显示用户开始答题后的消耗时间。 7)程序人机交互界面是GUI界面(WEB页面、APP页面都可),界面支持中文简体(必做)/中文繁体/英语,用户可以进行语种选择 二、软件设计: 1)流程图 2)类图(ContentToTxt():将内容写入文件 、ContinuTest():询问是否进行下一轮测试 、DTimeFrame():计时功能 、LoginIn():登录界面<登录账号:admin,密码:123456>、 PrintChart():绘制分数图、 ReadFile()

java笔试要点(java.sql包)

只谈情不闲聊 提交于 2020-05-08 02:20:36
提供 JAVA存取数据库能力的包是 ( ) A: java.sql B: java.awt C: java.lang D: java.swing 解析: A,java.sql包提供Java存取数据库能力 B,java.awt包是java图形界面的包 C,java.lang是java语言的核心好,lang是language的简写 D,java.swing是经过java封装的与操作系统无关的图形界面包 注解: java.sql提供使用 JavaTM 编程语言访问并处理存储在数据源(通常是一个关系数据库)中的数据的 API。此 API 包括一个框架,凭借此框架可以动态地安装不同驱动程序来访问不同数据源。 java(TM),那个TM,指的是Trade Mark,也就是商标,以前是sun公司持有,现在卖给Oracle了。 java.sql 包中包含用于以下方面的 API: 通过 DriverManager 实用程序建立与数据库的连接 DriverManager 类:建立与驱动程序的连接 SQLPermission 类:代码在 Security Manager(比如 applet)中运行时提供权限,试图通过 DriverManager 设置一个记录流 Driver 接口:提供用来注册和连接基于 JDBC 技术(“JDBC驱动程序”)的驱动程序的 API,通常仅由 DriverManager

Java 图形化界面设计(GUI)实战练习(代码)

末鹿安然 提交于 2020-05-05 12:01:40
关于Java图形化界面设计,基础知识网上可搜,下面简单介绍一下重点概念,然后就由浅入深代码实例。 程序是为了方便用户使用的,Java引入图形化界面编程。 1.JFrame 是容器类 2.AWT 是抽象窗口组件工具包,是 Java 最早的用于编写图形节目应用程序的开发包。 3.Swing 是为了解决 AWT 存在的问题而新开发的包,它以 AWT 为基础的。 代码实例1: package com.zhouzhou; // 练习网格布局 import java.awt.* ; import javax.swing.* ; public class Demo9 extends JFrame { // 定义组件 int size = 9 ; JButton jbs[] = new JButton[size]; public static void main(String[] args) { // 创建实例 Demo9 de = new Demo9(); } // 构造函数 public Demo9() { // 创建组件 for ( int i = 0; i < size; i++ ) { jbs[i] = new JButton(String.valueOf(i)); } // 设置网格布局,这里只有前两个参数(行/列)3和3 的话,网格没有空隙 this .setLayout( new