如何捕获回车键,使用扫描仪作为控制台输入?

我想在控制台中捕获输入字符。 我正在输入2个字符串。 案例1. removestudent(按Enter键)从arrays列表中删除所有学生。 案例2. removestudent student1从数组列表中删除students1。 Scanner in=new Scanner(); type_op=in.next(); param=in.next(); if (type_op.equals(“removestudent”)) { //Calling remove student function and passing param over here. } 现在案例2工作正常。 但是,对于案例1,我希望当用户按Enter键时,param值为null。 然后我将param作为空值传递给我的删除函数并删除数组列表中的所有学生。 list1.clear(); 请帮助我知道如何获得此输入密钥。

如何在JPanel中制作半透明的内容?

关于JPanel中组件的显示我很困惑。 假设我创建了一个半透明度为0.8f的自定义JPanel,如下所示: – JPanel panel=new JPanel(){ @Override public void paint(Graphics g) { super.paint(g); BufferedImage img=(BufferedImage)createImage(getWidth(),getHeight()); Graphics2D g2=(Graphics2D) g.create(); g2.setComposite(AlphaComposite.SrcOver.derive(0.8f)); g2.drawImage(img,0,0,null); } @Override public Dimension getPreferredSize() { return new Dimension(300,300); } }; 现在我将其设置为框架的contentPane。 frame.setContentPane(panel); 现在我添加一些按钮。 frame.add(new JButton(“Click Here”)); frame.add(new JButton(“Click Here”)); frame.add(new JButton(“Click Here”)); frame.add(new JButton(“Click Here”)); 1)然后在输出中我为什么会得到半透明按钮?由于JPanel是单层的,当我覆盖它的paint方法然后添加按钮时我首先绘制半透明图像,按钮不能是半透明的,因为它们应该越过它。 2)同样在这4个按钮中只有2个是半透明的。为什么会有这样的偏袒? 3)如果我在添加这4个按钮之前还添加了一个表,那么一切都变得半透明。为什么? Object[] names = new Object[] { […]

Java:将背景图像添加到框架

可能重复: java摇摆背景图像 在帧上绘制自己的缓冲图像 我正在尝试在我的框架中添加背景图像,但我没有做过任何工作。 我设计了一个老虎机,由几个面板组成,添加到容器中。 现在,我正在尝试为框架添加一个漂亮的背景。 我尝试使用paint方法。 但是,由于我已经使用绘画方法来绘制卷轴图像,因此它不适用于背景。 我也试过添加一个JLabel,但是当我这样做时会覆盖所有内容或被覆盖,具体取决于我如何调用它。 以下是我的代码; 任何帮助都感激不尽: import javax.swing.event.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import sun.audio.*; public class SlotMachine extends JFrame { private Container c = getContentPane(); private ImageIcon handleIcon = new ImageIcon(“starWars/slot-handle.png”); private ImageIcon quitIcon = new ImageIcon(“starWars/quit2.jpg”); private ImageIcon logoIcon = new ImageIcon(“starWars/logo3.jpg”); private ImageIcon BG […]

不重新显示图像

大家好,我在这里有点堆叠。 当我运行程序并按下提交按钮时,它应该每2秒更换4张图片。但是它不会重新显示图像。 如果有人能帮我一把,那就太好了。 我正在使用eclipse,程序正在编译和运行。 这是代码。 /** Here is the GUI of the program * class name SlideShowGui.java * @author Kiril Anastasov * @date 07/03/2012 */ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class SlideShowGui extends JPanel implements ActionListener, Runnable { JLabel name, comments, images; JTextField namejtf, commentsjtf, captionjtf; JButton submit; ImageIcon pictures1, pictures2, […]

使用Spring框架的抽象工厂

我有一些抽象工厂 public interface AbstractViewersFactory { IAbstractShapeViewer createRectangle(BaseOperationsListener p); IAbstractShapeViewer createOval(BaseOperationsListener p); IAbstractShapeViewer createTriangle(BaseOperationsListener p); } 并实现了Draw2DViewersFactory 。 现在,我想创建一个类,负责按模型创建演示者/查看器并由Spring配置它。 所以,我需要在.xml配置中描述它应该调用的方法。 它可以是这样的(伪配置) model=Rectangle.class, method-for-viewer-create=”createRectangle” model=Oval.class, method-for-viewer-create=”createOval” 我怎么能这样做? 谢谢。

如何使用“构造函数”在“选择子句”中为多个表的选定列编写HQL JOIN查询

我正在使用Constructor() 在Select子句中为多个表的选定列编写HQL JOIN查询 我有以下实体 : 实体1:NotificationObject.java @Entity @Table(name=”notification_object”) public class NotificationObject implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue( strategy=GenerationType.IDENTITY ) @Column( columnDefinition=”INT(10) UNSIGNED” ) private Integer id; @Column( name=”entity_type_id”, columnDefinition=”TINYINT UNSIGNED”, nullable=false ) private Short entityTypeId; @Column( name=”entity_id”, columnDefinition=”INT(10) UNSIGNED”, nullable=false ) private Integer entityId; @DateTimeFormat( pattern=”yyyy-MM-dd” ) @Temporal( TemporalType.TIMESTAMP […]

Glassfish 3.1默认主体到角色映射

我正在使用glassfish和jaas模块。 我以这种方式配置了我的web.xml。 ALL Page for admin /* user BASIC file Administrator user 这意味着所有想要访问我的Web应用程序的用户都需要是组用户。 然后在glassfish控制台上我需要勾选选项:Configuration – > server-config – > security – > Default Principal To Role Mapping 我的问题是为什么我需要将此默认主体勾选到角色映射? 以及如何更改我的web.xml以避免勾选它? 非常感谢 卢瓦克

Java抛出错误“不是抽象的,并且不会覆盖中的抽象方法”

我无法编译下面编写的代码,Java总是抛出一个错误。 你能帮帮我吗(PS:我是Java新手,还处于学习阶段)。 如果在任何地方,我写错了代码,请帮我纠正它,这样我就能很好地学习它。 Error Thrown(4):1。加法不是抽象的,不会覆盖calci中的抽象方法Div() 减法不是抽象的,并且不会覆盖calci中的抽象方法Div() 除法不是抽象的,也不会覆盖calci中的抽象方法Div() 乘法不是抽象的,并且不会覆盖calci中的抽象方法Div() import java.util.Scanner; interface calci { void add(); void sub(); void mul(); void div(); } 加类 class addition implements calci { public void add() { System.out.println(“Enter two numbers:”); Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int n1= scn.nextInt(); int result = n+n1; System.out.println(“The Result of the […]

来自Java的学习iPhone编程的最佳方法是什么?

我已经开始阅读有关此主题的所有可用的Apple文档。 快速概述给了我一些大约8.000(八千)DIN A4 PDF页面。 大约10%的内容几乎与我的感觉相同。 经过两周的阅读,我发现我会忘记一周前我读过的内容。 除非我开始对知识做点什么,否则它就像是大脑的消耗。 你的学习策略是什么?

从另一个类向JButton添加actionListener

所以我有两个类testPanel和testFrame。 所有按钮都在testPanel类中。 我想将ActionListeners添加到testFrame类的Jbuttons中。 我该怎么做呢? パ: public class testPanel extends JPanel{ JLabel codeLbl = new JLabel(“Code”); JLabel titleLbl = new JLabel(“Title”); JLabel priceLbl = new JLabel(“Price”); JTextField codeTxt = new JTextField(20); JTextField titleTxt = new JTextField(20); JTextField priceTxt = new JTextField(20); JButton addBtn = new JButton(“Add”); JButton updateBtn = new JButton(“Update”); JButton delBtn = new JButton(“Delete”); […]