بســم الله الـرحمــن الرحيــم
السلام عليكــم ورحمـة الله وبركاتــه
ok will the question is that we have to write a program that has two buttons Start and stop
and a text area and a text field the text field is where we have to write a file name into the text field and look for it if the file does not exist an IOexception is thrown and has to be dealt with by displaying an error message and asking for another file name, if the file does exist the content of the file will be loaded into the text area. when the user push the start button the text will scroll along the box until the user press the stop button. i will need to use at least two threads, one to cope with listening for events (buttons being pressed) and one to display the text.
- import java.io.*;
- import java.awt.event.*;
- import javax.swing.*;
- import java.awt.*;
- public class Layout{
- private JFrame frame;
- private JTextField fileName;
- private JTextArea filename;
- private JButton button1;
- private JButton button2;
- String directory;
- public Layout(String filename) {
- this(NULL, filename);
- }
- public Layout(){
- makeFrame();
- }
- public Layout(String directory, String filename){
- super();
- }
- private void makeFrame(){
- frame = new JFrame("Assignment 1");
- fileName = new JTextField(20);
- filename = new JTextArea("", 24, 80);
- JScrollPane scrollingResult = new JScrollPane(filename);
- Container contentPane = frame.getContentPane();
- JButton button1 = new JButton("Start");
- button1.setActionCommand("Start");
- button1.addActionListener(start);
- JButton button2 = new JButton("Stop");
- button2.setActionCommand("Stop");
- button2.addActionListener(stop);
- contentPane.setLayout(new FlowLayout());
- contentPane.ADD(button1);
- contentPane.ADD(button2);
- contentPane.ADD(fileName);
- contentPane.ADD(filename);
- filename.setEditable(false);
- frame.setVisible(true);
- frame.setSize(300,300);
- }
- public static void main(String[] args){
- Layout layout = new Layout();
- }
- ActionListener start = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- };
- ActionListener stop = new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- };
- }
- ارجو المساعدة باسرع وقت ممكن لاني جربت كثير لي اسبوع وانا اجرب فيه

