Multiple Choice Java Swing

вторник 12 маяadmin

Java Multiple Choice Questions and Answers GUI Swing - wadiemendja/Multiple-Choice-Quiz. Import javax.swing.; import java.awt.event. Public class MultipleChoice extends JApplet // GUI components JPanel upper, middle; JTextArea outputArea,. Nike sq sumo square 5900 driver for mac.

In the previous program, you have seen JList with single selection. Now let us go for JList Multiple Selection.

In the following JList Multiple Selection example, user’s multiple selected items are displayed in JOptionPane using showMessageDialog() method.

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
importjava.awt.*;
importjavax.swing.event.*;// for ListSelectionListener
publicclassMultiSelectionDemoextendsJFrameimplementsListSelectionListener
JList places;
publicMultiSelectionDemo()
Containerc=getContentPane();
Stringnames[]={'Banglore','Hyderabad','Ooty','Chennai','Mumbai','Delhi','Kochi','Darjeeling'};
places=newJList(names);// creating JList object; pass the array as parameter
places.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
c.add(newJScrollPane(places));
places.addListSelectionListener(this);
setTitle('Practcing Multiple selection JList');
setVisible(true);
publicvoidvalueChanged(ListSelectionEvente)
Stringdestinations=';
for(inti=0;i<obj.length;i++)
destinations+=(String)obj[i];
JOptionPane.showMessageDialog(null,'You go: '+destinations,'Learning Multiple Selections',JOptionPane.PLAIN_MESSAGE);
publicstaticvoidmain(Stringargs[])
newMultiSelectionDemo();
}

places.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

The above statement allows the list for multiple selections. By clicking an item in the list, holding shift key and clicking on another item, makes a contiguous selection of items. To deselect, hold the ctrl key and click again.

Object obj[] = places.getSelectedValues();

getSelectedValues() method of JList returns an array of objects of Object class(of selected items).

destinations += (String) obj[i];

Object element is casted to String object and concatenated.

Following are the methods provided by JList to know the user’s selection:

Selection

1. getSelectedValues() : returns an object array of selected items. Konica minolta c450 vxl printer driver for mac. Convert them into string.
2. getSelectedValue() : returns an object of the seleced item and convert it into string.
3. getSelectedIndexes() : returns an int array.
4. getSelectedIndex() : returns an int.

Java Programming : java.awt and java.io : Multiple Choice

FormatsInfo PageWorksheet / Test PaperQuizReview

Hide all answersView all answersPrintTry the Quiz

Learn about java.awt and java.io packages.


1. When we invoke repaint() for a java.awt.Component object, the AWT invokes the method:
• draw()
• show()
• paint()
• update()
Answer:update()

2. What does the following line of code do?
Textfield text = new Textfield(10);
• Creates text object that can hold 10 columns of text.
• Creates text object that can hold 10 rows of text.
• Creates the object text and initializes it with the value 10.
• The code is illegal.
Answer:Creates text object that can hold 10 columns of text.

3. Which of the following applet tags is legal to embed an applet class named Test into a Web page?
• < applet
class = Test width = 200 height = 100>
• < applet>
code = Test.class width = 200 height = 100>
• < applet
code = Test.class width = 200 height = 100
• < applet
param = Test.class width = 200 height = 100>
• < applet
code = Test.class width = 200 height = 100>
Answer:< applet
code = Test.class width = 200 height = 100>

4. Which of the following methods can be used to draw the outline of a square within a java.awt.Component object?
(A) fillRect()
(B) drawLine()
(C) drawRect()
(D) drawString()
(E) drawPolygon()
• (B), (C) & (E)
• (A), (B), (C) & (E)
• (A), (B) & (C)
• (C), (D) & (E)
• (B) & (C)
5. Which of the following methods can be used to change the size of a java.awt.Component object?
(A) dimension()
(B) setSize()
(C) area()
(D) size()
(E) resize()
• (A), (B), (C) & (E)
• (A), (B) & (E)
• (B), (D) & (E)
• (D) & (E)
• (B) & (E)
Answer:(B) & (E)

6. Which of the following methods can be used to remove a java.awt.Component object from the display?
• delete()
• hide()
• remove()
• disappear()
• move()
7. The setBackground() method is part of the following class in java.awt package:
• Graphics
• Component
• Applet
• Container
• Object
Answer:Component

8. Which of the following strings can be used as mode strings for creating a RandomAccessFile object?
(A) 'r'
(B) 'w'
(C) 'rw'
(D) 'wr'
(E) '0'
• (A), (B), (C) & (E)
• (A) & (C)
• (A), (B) & (C)
• (B), (D) & (E)
• (C) & (D)
9. DataInput is
• an abstract class defined in java.io.
• an interface that defines methods to read primitive data types.
• a class we can use to read primitive data types.
• an interface that defines methods to open files.
Answer:an interface that defines methods to read primitive data types.

10. Which of the following statements are true?
(A) Unicode characters are all 16 bits.
(B) UTF characters are all 24 bits.
(C) Reader class has methods that can read integers and floats.
(D) File class may be used to rename a file.
(E) DataOutputStream objects are used to write primitive data to a file.
• (A), (C), (D) & (E)
• (A), (B) & (D)
• (A), (D) & (E)
• (B), (D) & (E)
• (A) & (D)
11. Which are the valid ways to create DataInputStream streams?
• new DataInputStream();
• new DataInputStream('in.dat', 'r');
• new DataInputStream(new FileInputStream('in.dat');
• new DataInputStream('in.dat')
• new DataInputStream(new File('in.dat'));
Answer:new DataInputStream(new FileInputStream('in.dat');

12. Which exception is thrown by the read() method of InputStream class?
• IOException
• Exception
• FileNotFoundException
• ReadException
• None of these
13. If you want to assign a value of 99 to the variable year, then which of the following lines can be used within an tag?
• number = getParameter(99)
• < number = 99 >
• < param = radius value = 99 >
• < param number = 99 >
• < param name = number value = 99 >
Answer:< param name = number value = 99 >

14. Given file is a File object, which of the following are legal statements to create a new file?
(A) file.create();
(B) FileOutputStream fos = new FileOutputStream(file);
(C) FileWrter out = new FileWriter(file);
(D) FileInputStream fis = new FileInputStream(file);
(E) RandomAccessFile raf = new RandomAccessFile(file);
• (A), (B), (D) & (E)
• (B), (C) & (D)
• (B), (D) & (E)
• (B) & (C)
• (B), (C) & (E)