- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在查看与此类似错误有关的先前问题,但我无法找到未正确声明或使用的变量。我的程序目前只有四个选项,问题是第一个图像是唯一要显示的图像,然后出现错误。我已经尝试重写此代码几次,但似乎无法避免此错误。其他问题或代码似乎没有帮助。
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {
waitTime = Integer.valueOf(lblWaitput.getText());
if (waitTime <= 0){
waitTime = 60;
}
// METHOD TO CLEAR UP DEBRIS AND TO SPLIT INTO ARRAY
temp = txtList.getText();
temp = temp.toLowerCase();
selects = temp.split(" ");
for (i = 0; i < selects.length; i++){ //CLEANS UP VARIABLES FOR A PROPER PATH TO GRAB IMAGES FROM
selects[i] = "/SlideShow/" + selects[i] + ".jpg";
selectcount++;
} // END OF CLEANING
//START OF SLIDE SHOW
for (x = 0; x <= selectcount; x++){//THE LOOP THAT CYCLES THROUGH THE IMAGES
lblDisplay.setIcon(null);
System.out.println(selects[x]); //THE VARIABLE WHICH THE IMAGE IS IN
lblDisplay.setIcon(new javax.swing.ImageIcon(getClass().getResource(selects[x]))); //DISPLAYING IMAGE
try {
Thread.currentThread().wait(waitTime*10);
}
catch(InterruptedException ie){
}
}
// END OF SLIDES NOTHING FURTHER
}
下面是我的完整代码。
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package SlideShow;
import javax.swing.*;
/**
*
* @author palaceag196
*/
public class MainSlides extends javax.swing.JFrame {
String[] options = {"Soccer","Basketball","Football","Hockey","Ravioli","Banana","Pizza","Hotdog","Cat","Dog","Bird","Hamster"};
String temp;
String[] selects;
int selectcount;
int i, x;
int waitTime;
// new ImageIcon(getClass().getResource(temp))
/**
* Creates new form MainSlides
*/
public MainSlides() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
listSelect = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
txtList = new javax.swing.JTextArea();
lblWaitput = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
btnStart = new javax.swing.JButton();
lblDisplay = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
listSelect.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Soccer", "Basketball", "Football", "Hockey", "Ravioli", "Banana", "Pizza", "Hotdog", "Cat", "Dog", "Bird", "Hamster" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
listSelect.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
listSelectMouseClicked(evt);
}
});
jScrollPane1.setViewportView(listSelect);
txtList.setColumns(12);
txtList.setFont(new java.awt.Font("Monospaced", 0, 12)); // NOI18N
txtList.setLineWrap(true);
txtList.setRows(12);
txtList.setAutoscrolls(false);
txtList.setFocusable(false);
jScrollPane2.setViewportView(txtList);
lblWaitput.setText("60");
lblWaitput.setToolTipText("Input wait time here.");
jLabel1.setText("Wait Time:");
btnStart.setText("Start The Show");
btnStart.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnStartActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblWaitput, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
.addComponent(btnStart))
.addComponent(lblDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblWaitput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addComponent(btnStart))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
pack();
}// </editor-fold>
private void listSelectMouseClicked(java.awt.event.MouseEvent evt) {
txtList.setText(txtList.getText() + options[listSelect.getSelectedIndex()] + " ");
// TODO add your handling code here:
}
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {
waitTime = Integer.valueOf(lblWaitput.getText());
if (waitTime <= 0){
waitTime = 60;
}
// METHOD TO CLEAR UP DEBRIS AND TO SPLIT INTO ARRAY
temp = txtList.getText();
temp = temp.toLowerCase();
selects = temp.split(" ");
for (i = 0; i < selects.length; i++){ //CLEANS UP VARIABLES FOR A PROPER PATH TO GRAB IMAGES FROM
selects[i] = "/SlideShow/" + selects[i] + ".jpg";
selectcount++;
} // END OF CLEANING
//START OF SLIDE SHOW
for (x = 0; x <= selectcount; x++){//THE LOOP THAT CYCLES THROUGH THE IMAGES
lblDisplay.setIcon(null);
System.out.println(selects[x]); //THE VARIABLE WHICH THE IMAGE IS IN
lblDisplay.setIcon(new javax.swing.ImageIcon(getClass().getResource(selects[x]))); //DISPLAYING IMAGE
try {
Thread.currentThread().wait(waitTime*10);
}
catch(InterruptedException ie){
}
}
// END OF SLIDES NOTHING FURTHER
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainSlides.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainSlides.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainSlides.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainSlides.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainSlides().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnStart;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lblDisplay;
private javax.swing.JTextField lblWaitput;
private javax.swing.JList listSelect;
private javax.swing.JTextArea txtList;
// End of variables declaration
}
最佳答案
关于java - 不断出现错误 Exception in thread "AWT-EventQueue-0"java.lang.IllegalMonitorStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41226152/
AWT-EventQueue 线程和 AWT-Shutdown 线程没有在我们的应用程序中关闭。有没有一种调试技术可以找出它们不存在的原因?有什么特别的东西要寻找吗? 最佳答案 如果你的意思是关闭所有
java.awt.* 和 java.awt.event.* 有什么区别? 最佳答案 这只是两个不同的包。 当您说import java.awt.*时,它仅导入那些完全属于java.awt包的类,而不是
我正在将 aadhar 集成到 liferay 中。我尝试了这个链接 https://developer.uidai.gov.in/site/book/export/html/18 所以我想将其集成到
我想知道如何确定 Java.awt.Rectangle 是否包含特定 Java.awt.Color 的像素。我一直在到处寻找,但找不到任何关于此的信息,甚至找不到任何可能的信息。 所以我想知道如何确定
我试图在组件和图像之间切换面板的内容,它适用于组件: imgpanel.removeAll(); Component comp; if ((comp = player.getVisualCompone
我在使用 JAVA 编码时遇到一些错误,我一直在尝试解决这个问题,也试图找到其他有同样问题的人并修复它,但没有任何效果... 嗯..这是代码 package ca.vanzeben.game;
我想我可以尝试一下 JAXB 来处理存储和恢复设置。但即使是“最简单”的例子我也遇到了麻烦: import java.awt.Point; public class Config { public
这个问题已经有答案了: Import package.* vs import package.SpecificType [duplicate] (10 个回答) 已关闭 7 年前。 在我现在正在进行的
private static byte[] get_byte_data(BufferedImage image) { //WritableRaster raster = image.get
是否有可能获得标准 AWT Cursor以位图图像的形式(例如 BufferedImage )或任何可在 Graphics2D 上绘制的图像?例如,文本光标 new Cursor(Cursor.TEX
我的代码中有三个点,我想填充它们之间的区域,或者换句话说,在 3 个点之间绘制并填充一个三角形。 我想过简单地用 for 循环绘制线条(从 x1 到 x2),但我认为这不会有效,是否有其他更有效的方法
我正在制作一个小脚本,我使用鼠标键来节省我的工作时间。我可以正确、良好地使用鼠标键。但是,当使用 java.awt.Robot 和 java.awt.event.KeyEvent 时,鼠标键基本上被忽
我正在尝试在 scala 中使用 java awt 来制作一个简单的桌面应用程序。我已经在它上面工作了几天,没有任何问题,直到我有 2 天没有碰它,当我回来时,我得到一个 java.lang.NoCl
我在 VisualVM 和线程 View 中监视一个 JavaFX 程序,不断有 AWT-EventQueue-0 和 AWT-Shutdown 线程被创建和销毁。这是正常行为吗?这是什么原因? 最佳
我需要将 java.awt.geom.Area 或 java.awt.Shape 转换为 java.awt.Polygon。我所知道的是:isSingular = true、isPolygonal =
我正在重新使用 Java 并审查我的一些旧代码,并且我看到了很多我已经完成的地方 import javax.swing.*; import java.awt.*; 或者实际上从 swing/awt 包
晚上, 我在玩一个小的 swing 应用程序,我添加了一个按钮来响应按下。因此我需要实现 ActionListener。我已经添加了这一行: import java.awt.*; 但它告诉我找不到“A
我有这个 java 代码: Editor() { javax.swing.SwingUtilities.invokeLater(new Runnable() { pub
请帮我解决这个问题 sun.awt.image.ToolkitImage 无法转换为 java.awt.image.BufferedImage if (shape.hasImage())
嗨 Stackoverflow 的 friend 们 我最近将 Jenkins 服务器配置到 Apache Tomcat 7.0.42我制作的程序是将 jenkins.war 文件部署到 tomcat
我是一名优秀的程序员,十分优秀!