- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
/*
* IntegerSumsView.java
* This is a program that allows an individual to add a list of numbers, and choose whether
* they add all numbers, or only even or odd numbers
*/
public class IntegerSumsView extends FrameView {
//
int position = 0;
int[] aryInteger = new int[10];
public IntegerSumsView(SingleFrameApplication app) {
super(app);
initComponents();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = IntegerSumsApp.getApplication().getMainFrame();
aboutBox = new IntegerSumsAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
IntegerSumsApp.getApplication().show(aboutBox);
}
/** 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() {
mainPanel = new javax.swing.JPanel();
integerLabel = new javax.swing.JLabel();
enterIntField = new javax.swing.JTextField();
addIntButton = new javax.swing.JButton();
sumAllButton = new javax.swing.JButton();
userOutputField = new javax.swing.JTextField();
sumEvenButton = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
userOutputArea = new javax.swing.JTextArea();
sumOddButton = new javax.swing.JButton();
removeIntButton = new javax.swing.JButton();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(integersums.IntegerSumsApp.class).getContext().getResourceMap(IntegerSumsView.class);
integerLabel.setText(resourceMap.getString("integerLabel.text")); // NOI18N
integerLabel.setName("integerLabel"); // NOI18N
enterIntField.setText(resourceMap.getString("enterIntField.text")); // NOI18N
enterIntField.setName("enterIntField"); // NOI18N
addIntButton.setText(resourceMap.getString("addIntButton.text")); // NOI18N
addIntButton.setName("addIntButton"); // NOI18N
addIntButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addIntButtonActionPerformed(evt);
}
});
sumAllButton.setText(resourceMap.getString("sumAllButton.text")); // NOI18N
sumAllButton.setName("sumAllButton"); // NOI18N
sumAllButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sumAllButtonActionPerformed(evt);
}
});
userOutputField.setText(resourceMap.getString("userOutputField.text")); // NOI18N
userOutputField.setName("userOutputField"); // NOI18N
sumEvenButton.setText(resourceMap.getString("sumEvenButton.text")); // NOI18N
sumEvenButton.setName("sumEvenButton"); // NOI18N
sumEvenButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sumEvenButtonActionPerformed(evt);
}
});
jScrollPane1.setName("jScrollPane1"); // NOI18N
userOutputArea.setColumns(20);
userOutputArea.setRows(5);
userOutputArea.setName("userOutputArea"); // NOI18N
jScrollPane1.setViewportView(userOutputArea);
sumOddButton.setText(resourceMap.getString("sumOddButton.text")); // NOI18N
sumOddButton.setName("sumOddButton"); // NOI18N
sumOddButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sumOddButtonActionPerformed(evt);
}
});
removeIntButton.setText(resourceMap.getString("removeIntButton.text")); // NOI18N
removeIntButton.setName("removeIntButton"); // NOI18N
removeIntButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeIntButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(userOutputField, javax.swing.GroupLayout.DEFAULT_SIZE, 372, Short.MAX_VALUE)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
.addComponent(addIntButton)
.addGap(89, 89, 89))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(sumAllButton)
.addGap(73, 73, 73))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(sumEvenButton)
.addGap(61, 61, 61))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(sumOddButton)
.addGap(65, 65, 65)))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(integerLabel)
.addGap(18, 18, 18)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(removeIntButton)
.addComponent(enterIntField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(48, 48, 48)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(integerLabel)
.addComponent(enterIntField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(36, 36, 36)
.addComponent(removeIntButton))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(addIntButton)
.addGap(8, 8, 8)
.addComponent(sumAllButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sumEvenButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sumOddButton)))
.addGap(19, 19, 19))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)))
.addComponent(userOutputField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(17, Short.MAX_VALUE))
);
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(integersums.IntegerSumsApp.class).getContext().getActionMap(IntegerSumsView.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(statusMessageLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(statusPanelLayout.createSequentialGroup()
.addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(statusMessageLabel)
.addComponent(statusAnimationLabel)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3))
);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void addIntButtonActionPerformed(java.awt.event.ActionEvent evt) {
//I apologize if these comments are a little imformal...or doesn't quite make sense, I'm fairly new at this
//Here, you add any integer into the enterIntField, and after pressing the addIntButton, the integer is inputted into the
//userOutputArea,
//the "null" is for when you go to add a second integer, it does not input both first integer again ( as well as the second integer)
//you can add up to 10 different variables.
//Now I would also like to say I apologize if my any of my terminology is wrong...or makes no sense
aryInteger[position] = Integer.parseInt(enterIntField.getText());
position ++;
userOutputArea.setText(null);
for (int i = 0; i < position; i++) {
userOutputArea.setText(userOutputArea.getText() + aryInteger[i] + "\n");
}
}
private void sumAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
//this adds all numbers inputted and outputs it the userOutputField...
int sumall = 0;
for(int i = 0; i < position; i++)
{
sumall += aryInteger[i];
}
userOutputField.setText("The sum of all numbers is " + sumall);
}
private void sumEvenButtonActionPerformed(java.awt.event.ActionEvent evt) {
//add all even numbers
int sumeven = 0;
for(int i = 0; i < position; i++)
{
if(aryInteger[i]%2==0) {
sumeven += aryInteger[i];
}
}
userOutputField.setText("The sum of all even numbers is " + sumeven);
}
private void sumOddButtonActionPerformed(java.awt.event.ActionEvent evt) {
//adds only the odd numbers...
int sumodd = 0;
for(int i = 0; i < position; i++)
{
if(aryInteger[i]%2!=0) {
sumodd += aryInteger[i];
}
}
userOutputField.setText("The sum of all odd numbers is " + sumodd);
}
问题就在下面......
private void removeIntButtonActionPerformed(java.awt.event.ActionEvent evt) {
在这里,我想创建一个“删除”按钮,用于取出已在 userOutputArea 中输入的所有整数。 这样用户就可以从头开始,而不必退出程序并重新打开它。
我最初认为它会是“i”,因为这就是变量/字母用于在“addIntButtonActionPerformed”下面添加整数的地方 ...但话又说回来,也许“i”只是强调了,因为在公共(public)课下没有提到它?但我会在那里添加什么 没有弄乱其他任何东西?然而,这对我来说是最有意义的......这只是我用 java 编写的第五个程序,所以我认为很有可能是严重错误的。我知道这很可悲,但老实说,这是我目前最好的尝试,在等待回复时我仍在尝试。即使是一个小小的提示也将不胜感激!
aryInteger.remove(i);
}
// 3 5 6 8 9
// Variables declaration - do not modify
private javax.swing.JButton addIntButton;
private javax.swing.JTextField enterIntField;
private javax.swing.JLabel integerLabel;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JButton removeIntButton;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
private javax.swing.JButton sumAllButton;
private javax.swing.JButton sumEvenButton;
private javax.swing.JButton sumOddButton;
private javax.swing.JTextArea userOutputArea;
private javax.swing.JTextField userOutputField;
// End of variables declaration
最佳答案
您似乎想清除JTextArea
类型组件userOutputArea
。如果我做对了,那么这行代码应该可以做到:
userOutputArea.setText("");
如果您有其他意思,请进一步澄清您的任务。
关于java - 如何从文本区域中删除输入的数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824202/
我需要将文本放在 中在一个 Div 中,在另一个 Div 中,在另一个 Div 中。所以这是它的样子: #document Change PIN
奇怪的事情发生了。 我有一个基本的 html 代码。 html,头部, body 。(因为我收到了一些反对票,这里是完整的代码) 这是我的CSS: html { backgroun
我正在尝试将 Assets 中的一组图像加载到 UICollectionview 中存在的 ImageView 中,但每当我运行应用程序时它都会显示错误。而且也没有显示图像。 我在ViewDidLoa
我需要根据带参数的 perl 脚本的输出更改一些环境变量。在 tcsh 中,我可以使用别名命令来评估 perl 脚本的输出。 tcsh: alias setsdk 'eval `/localhome/
我使用 Windows 身份验证创建了一个新的 Blazor(服务器端)应用程序,并使用 IIS Express 运行它。它将显示一条消息“Hello Domain\User!”来自右上方的以下 Ra
这是我的方法 void login(Event event);我想知道 Kotlin 中应该如何 最佳答案 在 Kotlin 中通配符运算符是 * 。它指示编译器它是未知的,但一旦知道,就不会有其他类
看下面的代码 for story in book if story.title.length < 140 - var story
我正在尝试用 C 语言学习字符串处理。我写了一个程序,它存储了一些音乐轨道,并帮助用户检查他/她想到的歌曲是否存在于存储的轨道中。这是通过要求用户输入一串字符来完成的。然后程序使用 strstr()
我正在学习 sscanf 并遇到如下格式字符串: sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c); 我理解 %[^:] 部分意味着扫描直到遇到 ':' 并将其分配给 a。:
def char_check(x,y): if (str(x) in y or x.find(y) > -1) or (str(y) in x or y.find(x) > -1):
我有一种情况,我想将文本文件中的现有行包含到一个新 block 中。 line 1 line 2 line in block line 3 line 4 应该变成 line 1 line 2 line
我有一个新项目,我正在尝试设置 Django 调试工具栏。首先,我尝试了快速设置,它只涉及将 'debug_toolbar' 添加到我的已安装应用程序列表中。有了这个,当我转到我的根 URL 时,调试
在 Matlab 中,如果我有一个函数 f,例如签名是 f(a,b,c),我可以创建一个只有一个变量 b 的函数,它将使用固定的 a=a1 和 c=c1 调用 f: g = @(b) f(a1, b,
我不明白为什么 ForEach 中的元素之间有多余的垂直间距在 VStack 里面在 ScrollView 里面使用 GeometryReader 时渲染自定义水平分隔线。 Scrol
我想知道,是否有关于何时使用 session 和 cookie 的指南或最佳实践? 什么应该和什么不应该存储在其中?谢谢! 最佳答案 这些文档很好地了解了 session cookie 的安全问题以及
我在 scipy/numpy 中有一个 Nx3 矩阵,我想用它制作一个 3 维条形图,其中 X 轴和 Y 轴由矩阵的第一列和第二列的值、高度确定每个条形的 是矩阵中的第三列,条形的数量由 N 确定。
假设我用两种不同的方式初始化信号量 sem_init(&randomsem,0,1) sem_init(&randomsem,0,0) 现在, sem_wait(&randomsem) 在这两种情况下
我怀疑该值如何存储在“WORD”中,因为 PStr 包含实际输出。? 既然Pstr中存储的是小写到大写的字母,那么在printf中如何将其给出为“WORD”。有人可以吗?解释一下? #include
我有一个 3x3 数组: var my_array = [[0,1,2], [3,4,5], [6,7,8]]; 并想获得它的第一个 2
我意识到您可以使用如下方式轻松检查焦点: var hasFocus = true; $(window).blur(function(){ hasFocus = false; }); $(win
我是一名优秀的程序员,十分优秀!