Java GUI Application Testing (Not an Applet) Create a Java GUI application named
ID: 3676862 • Letter: J
Question
Java GUI Application Testing (Not an Applet)
Create a Java GUI application named VowelApplication.java. You program must be able to count the a, e, i, o, u, A, E, I, O, and U in the typed text in the text area or the selected textbooks in the JList. Finally it must give a total count of the vowels as shown in screenshot.
Create 4 JPanels and add them to the pane. You can add the GUI components to the correct panels. The labels occupy ¼ and the text area occupies ¾ of panels 1 and 3. Use appropriate Fonts and Colors as needed in your GUI. Place two JLists and a button in Panel 2 and four buttons in Panel 4.
Each button is marked clearly and must also display a tool tip. Use Appropriate Font and Color in your program.
Note:
You will need only one ActionListener for the whole program.
You don’t need any ListSelectionListener.
Don’t use deprecated methods in your program. Usually IDE will have a Strikethrough of the deprecated methods.
Find Vowels in TextArea
In Panel1 text area, the user enters a paragraph of text and when he/she clicks the Find Vowels in Text Area button, the Text Area in Panel 3 will display the count of a, e, i, o, u, A, E, I, O, U and the total number of vowels.
You must code a method FindVowels that will return a String in your program and use it. The label in Panel3 will display “Vowels in the given text”. The button (Find Vowels in JList) will become inactive. Only three buttons will be active.
Find Vowels in JList textbooks selected
The user selects the textbooks in JList on the left and clicks the books by either holding the Shift (contiguous) or Ctrl (noncontiguous) keys. The user may select multiple books from this list. Upon clicking the copy button, the list of textbook selected is copied into the JList on the right.
The textbooks to be loaded in JList on the left are given in the table.
Beginning Java Programming
Beginning Programming with Java for Dummies
Java Programming: From Problem Analysis to Program Design
Head First Java
Java The Complete Reference
Introduction to Java Programming Comprehensive
An Introduction to Programming Using Java
Effective Java
Core Java Volume 1 Fundamentals
Java in 21 Days, Sam’s Teach Yourself
Once the textbooks are selected, the user must click the copy >>> button to move it to the JList on right. Once the JList on right is not empty, the Find Vowels in Text button must become inactive.
Clear Button
The clear Button will clear the text area in Panel 1, the JList on the right, the label and textArea in Panel 3 and make both the Find button enabled. The copy button also becomes active.
Exit Button
Clicking this button exits the application.
Beginning Java Programming
Beginning Programming with Java for Dummies
Java Programming: From Problem Analysis to Program Design
Head First Java
Java The Complete Reference
Introduction to Java Programming Comprehensive
An Introduction to Programming Using Java
Effective Java
Core Java Volume 1 Fundamentals
Java in 21 Days, Sam’s Teach Yourself
Find Vowels Panel 1 has a label and TextArea Enter a paragraph of text in the textArea: Beginning Java Programming Beginning Programming with Java for Java Programming: From Problem A Head First Java Panel 2 has 2 JLists and one button. The scrollpane of JList on right will turn on after you copy the textbooks. Copy Panel 3 has a label and TextArea Panel 4 has 4 buttons Find Vowels In TextArea Find Vowels in List Clear ExitExplanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package program1gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
/**
*
* @author PINERONE
*/
public class VowelApplication extends javax.swing.JFrame implements ActionListener{
/**
* Creates new form VowelApplication
*/
public VowelApplication() {
initComponents();
jLabel2.setText("<html><body>Enter a paragraph of <br>text in the textArea: </body></html>");
jButton1.setText("<html><body> Copy <br> >>>> </body></html>");
jButton1.addActionListener(this);
jButton2.addActionListener(this);
jButton3.addActionListener(this);
jButton4.addActionListener(this);
jButton5.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source==jButton1){
/*jList2.setListData((String[]) jList1.getSelectedValues());
jButton2.setEnabled(false);
jLabel1.setText("<html><body>Vowels in the <br>selected list: </body></html>");*/
}
if (source==jButton2){
System.out.print("pulsado boton 2");
if (jTextArea1.getText() != ""){
jLabel1.setText("<html><body>Vowels in thegiven text: </body></html>");
jButton1.setEnabled(false);
jButton3.setEnabled(false);
jTextArea2.setText(findVowels(jTextArea1.getText()));
}
}
if (source==jButton3){
/*jButton2.setEnabled(false);
jLabel1.setText("<html><body>Vowels in the <br>selected list: </body></html>");*/
}
if (source==jButton4){
jLabel1.setText("");
jTextArea1.setText("");
jTextArea2.setText("");
jButton1.setEnabled(true);
jButton2.setEnabled(true);
jButton3.setEnabled(true);
jButton4.setEnabled(true);
jButton5.setEnabled(true);
}
if (source==jButton5){
System.exit( 0 );
}
}
public String findVowels(String data){
String result="";
int a,e,i,o,u;
a=e=i=o=u=0;
data = data.toUpperCase();
for (int j=0; j<data.length(); j++){
switch(data.charAt(j)){
case 'A' : a++; break;
case 'E' : e++; break;
case 'I' : i++; break;
case 'O' : o++; break;
case 'U' : u++; break;
default : break;
}
}
result = "The number of a's: "+a+
" The number of e's: "+e+
" The number of i's: "+i+
" The number of o's: "+o+
" The number of u's: "+u+
" The total vowels: "+(a+e+i+o+u);
return result;
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
jList2 = new javax.swing.JList<>();
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList<>();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();
jTextArea2 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Find Vowels");
setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBackground(new java.awt.Color(204, 204, 204));
jTextArea1.setBackground(new java.awt.Color(102, 255, 255));
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel2.setToolTipText("");
jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
);
jScrollPane3.setViewportView(jList2);
jButton1.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
jButton1.setText("Copy");
jList1.setModel(new javax.swing.AbstractListModel<String>() {
String[] strings = { "Beginning Java Programming", "Beginning Programming with Java for Dummies", "Java Programming: From Problem Analysis to Program Design", "Head First Java", "Java The Complete Reference", "Introduction to Java Programming Comprehensive", "An Introduction to Programming Using Java", "Effective Java", "Core Java Volume 1 Fundamentals", "Java in 21 Days, Sam’s Teach Yourself" };
public int getSize() { return strings.length; }
public String getElementAt(int i) { return strings[i]; }
});
jScrollPane2.setViewportView(jList1);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(27, 27, 27))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
);
jPanel3.setBackground(new java.awt.Color(204, 204, 204));
jTextArea2.setBackground(new java.awt.Color(255, 255, 102));
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane4.setViewportView(jTextArea2);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane4))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
);
jButton2.setText("Find Vowels in TextArea");
jButton3.setText("Find Vowels in List");
jButton4.setText("Clear");
jButton5.setText("Exit");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(41, 41, 41)
.addComponent(jButton3)
.addGap(51, 51, 51)
.addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(33, 33, 33)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(55, 55, 55))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>
/**
* @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(VowelApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VowelApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VowelApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VowelApplication.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 VowelApplication().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JList<String> jList1;
private javax.swing.JList<String> jList2;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
// End of variables declaration
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.