CS 102 Spring 2018 Take Home Quiz on GUI and IO 1. We have ctionListener PlayCar
ID: 3714564 • Letter: C
Question
CS 102 Spring 2018 Take Home Quiz on GUI and IO 1. We have ctionListener PlayCardListener Write the complete code of the PlayCardListener. (The method need not do anything.) 2. In the above problem, what the class PlayCardListener need to import? Write all needed import statements 3. If you need to use File type (of the java library) in your program, write the import statement. 4. We have JFrame CardHandFrame Write the code for the constructor of CardHandFrame class that it set title to be My Card Hand, and of initial size 400 by 400.Explanation / Answer
1)
class PlayCardListner implements ActionListener
{
JButton bChange;
PlayCardListner()
{
. . . . . .
}
// listener method for the ActionListener interface
public void actionPerformed( ActionEvent evt)
{
. . . . . .
}
}
2)
import java.awt.*;
import java.awt.event.*;
3)
import java.io.*;
4)
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Jpanel;
public class CardHandFrame {
public CardHandFrame(){
JFrame frame = new JFrame("JFrame DEMO");
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
frame.setSize(400, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String s[]) {
}
}
5) Jpanel
6)
import javax.swing.*;
public class JButtonExample {
public static void main(String[] args) {
JFrame f=new JFrame("JButton Example");
JButton b=new JButton("Mine");
b.setBounds(50,100,95,30);
f.add(b);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
7)
B)
picPanel.add(myButton)
8)
BufferReader and FileReader
import java.io.BufferedReader;
import java.io.FileReader;
9)
for byte stream
FileInputStream and FileOutputStream can be used
import java.io.FileInputStream;
import java.io.FileOutputStream;
10)
BufferedWriter and FileWriter
11)
File file = new File("myOut.txt");
12)
FileReader reader = new FileReader("D:\myin.txt");