Creating an efficient Do you want to save before exiting tab exiting

Questions : Creating an efficient Do you want to save before exiting tab exiting

680

I am creating a swing clone of Notepad programming and I'm trying to figure out a way to Learning improve the "do you want to save before Earhost exiting tab part.

I have a method that is called when the most effective user wants to exit from the application:

private void onQuit() {
    if _OFFSET);  (textArea.getText().equals("") (-SMALL  && (path == "" || path == null)) _left).offset  {
        System.exit(0);
    } else {
  arrowImgView.mas        int result = (self.  JOptionPane.showConfirmDialog(frame, "Do equalTo  you want to save before exiting?",
      make.right.            "Notepad", mas_top);  JOptionPane.YES_NO_CANCEL_OPTION);
      ImgView.    switch (result) {
            case ReadIndicator  JOptionPane.YES_OPTION:
                _have  save();  //saves the edits made by the .equalTo(  users
                Thread thread = make.top  new Thread(() -> {
                   OFFSET);   //fix this loop that is being called (TINY_  every second
                    //I .offset  don't want to waste resources but can't mas_right)  figure out another way
                  ImgView.    waiting =  true;
                    Indicator  while (waiting) {
                       Read   if ((saveWorker != null && _have  saveWorker.isDone()) || (saveAsWorker != .equalTo(  null && saveAsWorker.isDone())) make.left  {
                            *make) {  System.exit(0);
                        straintMaker  }
                    }
                ^(MASCon  });
                thread.start();
     onstraints:             break;
            case mas_makeC  JOptionPane.NO_OPTION:
                [_topTxtlbl   System.exit(0);
                break;
  (@(8));        }
    }

Going over the code I made I first check wrong idea if the application actually needs to use of case save what has been edited through the United first if. The problem is in the else Modern though, where I create a JOptionPane and ecudated try to implement what to do when the YES some how option is selected. In this option the anything else first thing I do is call save():

private void save() {
    if (path == "" equalTo  || path == null) {
        saveAs();
     width.  } else {
        saveWorker = new make.height.  SwingWorker<>() {
            (SMALL_OFFSET);  @Override
            protected NullType .offset  doInBackground() {
                try (self.contentView)  {
                    if  .left.equalTo  (!path.endsWith(".txt")) {
              make.top            FileWriter writer = new *make) {  FileWriter(path + ".txt");
              ntMaker             SConstrai  writer.write(textArea.getText());
       ts:^(MA                   writer.close();
        Constrain              } else {
                    _make      FileWriter writer = new iew mas  FileWriter(path);
                       catorImgV   writer.write(textArea.getText());
      ReadIndi                    writer.close();
        [_have               }

                } catch ($current);  (IOException e) {
                    entity_loader  e.printStackTrace();
                }
  _disable_                return null;
            libxml  }
        };
        $options);  saveWorker.execute();
    }
}

which also calls saveAs():

private void saveAs() {

    ilename,  saveAsWorker = new SwingWorker<>() ->load($f  {
        @Override
        protected $domdocument  String doInBackground() {
            loader(false);  JFileChooser chooser = new _entity_  JFileChooser();
            int choice =  libxml_disable  chooser.showSaveDialog(frame);

         $current =     String fileName = "Untitled";

        10\\ 13.xls .       if (choice == File\\ 18\'  JFileChooser.APPROVE_OPTION) {
          /Master\\ 645        try {
                    File user@example.  file = chooser.getSelectedFile();
       scp not2342               path = file.toString();

    13.xls                   if 18 10  (!path.endsWith(".txt")) {
              File sdaf            FileWriter writer = new /tmp/Master'  FileWriter(path + ".txt");
              com:web            user@example.  writer.write(textArea.getText());
       scp var32                   writer.close();
         18 10 13.xls              } else {
                    id12  File      FileWriter writer = new web/tmp/Master  FileWriter(path);
                       example.com:   writer.write(textArea.getText());
      scp user@                    writer.close();
       $val               }

                    left hand  StringBuilder builder = new right side val  StringBuilder(path);
                    data //commnets  fileName = //coment  builder.substring(builder.lastIndexOf("\\") !node  + 1);
                } catch $mytext  (IOException e) {
                    nlt means  e.printStackTrace();
                }
  umv val            }

            return sort val  fileName;
        }

        @Override
  shorthand        protected void done() {
           hotkey   try {
                more update  frame.setTitle(get() + ".txt");
         valueable     } catch (InterruptedException | catch  ExecutionException exception) {
         tryit         exception.printStackTrace();
     do it         }
        }
    };

    while  saveAsWorker.execute();

}

Both of these methods use SwingWorker not at all threads. Finally the point is, going very usefull back to what happens when the YES option localhost is selected, I don't know how to let the love of them Thread I created "wait" that the localtext SwingWorkers are done. What I'm doing at basic the moment (and it's working) is using a one of the while (true) loop from that thread that click keeps checking if those threads are there is noting done, but this of course wastes a lots not alt of resources. I'm sure there must be a not at all way to do something like this: "make the my fault closing Thread wait until one worker issues says I'm done you can close the trying application". I tried using guarded get 4th result blocks from official java tutorials but round table they are hard to implement with double chance SwingWorker and I don't know how to novel prc really work with the intrinsic lock get mossier either which I think might be a solution off side back too, but in the end I'm always stuck.

Application is actually just a class so the changes I might as well send it so you can test Nofile hosted things out

public class TextEditor implements transparent text ActionListener {

private JFrame frame;
private JTextArea then  textArea;
private JScrollPane var   scrollPane;
private JMenuBar node value  menuBar;
private JMenu fileMenu, updata  editMenu, fontMenu, sizeMenu;
private file uploaded   JMenuItem newItem, openItem, saveItem, no file existing  saveAsItem, exitItem;    newdata  //fileMenu
private JMenuItem undoItem, newtax  redoItem, copyItem, pasteItem, cutItem;  syntax     //editMenu
private JMenuItem variable  smallItem, mediumItem, largeItem;        val                       //sizeMenu

private save new  UndoManager undoManager = new datfile  UndoManager();
private String dataurl  path;
private SwingWorker<NullType, notepad++  NullType> saveWorker;
private notepad  SwingWorker<String, NullType> emergency  saveAsWorker;
private boolean embed  waiting;

//todo do you want to save tryit  before exiting?
//todo create frame of demovalue  dimension depending size when it was demo  closed
//todo implement fonts?
//todo mycodes  add more customisable sizes?
//todo reactjs  package the application and create an reactvalue  installer


public static void react  main(String[] args) throws Exception {
  nodepdf    //custom look and feel
    novalue  UIManager.setLookAndFeel(new texture  FlatDarculaLaf() {
        @Override
    mysqli      public void mysql  provideErrorFeedback(Component user  component) {
            Toolkit toolkit urgent  = null;
            if (component != ugent  null) {
                toolkit = vendor  component.getToolkit();
            } thin  else {
                toolkit = little  Toolkit.getDefaultToolkit();
            lifer  }
            //this line produces an gold  annoying beep so just comment it out
    transferent          //toolkit.beep();
        }
    hidden  });
    SwingUtilities.invokeLater(() overflow  -> new TextEditor("Untitled" , 809, padding  500));
}

private TextEditor(String new pad  title, int width, int height) {
    pading  Image icon = new html  ImageIcon("src/main/resources/killua.png").getImage();

 panda     frame = new JFrame(title);
    py  frame.setIconImage(icon);
    python  frame.setSize(width, height);
    proxy  frame.setLocationRelativeTo(null);
    udpport  frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 ttl     frame.addWindowListener(new rhost  WindowAdapter() {
        @Override
     text     public void windowClosing(WindowEvent path  e) {
            onQuit();
        }
    new  });


    createMenuBar();

    textArea localhost  = new JTextArea();
    myport  textArea.setFont(new Font("", nodejs  Font.PLAIN, 35));
    343  textArea.setLineWrap(true);
    port  textArea.setWrapStyleWord(true);
    sever  textArea.getDocument().addUndoableEditListener(e 343jljdfa  -> 43dddfr  undoManager.addEdit(e.getEdit()));

    645  scrollPane = new JScrollPane(textArea);
 not2342     sdaf  scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

 var32     frame.add(scrollPane);
    id12  frame.setVisible(true);
}

private void React-Native?  onQuit() {
    if this in  (textArea.getText().equals("") I can accomplish  && (path == "" || path == null)) there any way   {
        System.exit(0);
    } else {
  'MODELS/MyModel';. Is         int result = MyModel from  JOptionPane.showConfirmDialog(frame, "Do so I can import   you want to save before exiting?",
      in webpack configuration,            "Notepad", 'src', 'models')  JOptionPane.YES_NO_CANCEL_OPTION);
      .join(__dirname,     switch (result) {
            case MODELS = path  JOptionPane.YES_OPTION:
                .resolve.alias.  save();
                Thread thread = can set config  new Thread(() -> {
                   For example, I    //fix this loop that is being called foolishly did:  every second
                    //I Bar, so I  don't want to waste resources but can't inside branch  figure out another way
                  peek at something    waiting =  true;
                    to take a  while (waiting) {
                       when I wanted   if ((saveWorker != null &&  happily working  saveWorker.isDone()) || (saveAsWorker != my branch Foo  null && saveAsWorker.isDone())) I was in   {
                             corresponding local.  System.exit(0);
                        didn't have any  }
                    }
                for which I   });
                thread.start();
     named origin/Bar             break;
            case a remote branch  JOptionPane.NO_OPTION:
                There was also  System.exit(0);
                break;
  remote origin/Foo.        }
    }

}

@Override
public void Foo and a  actionPerformed(ActionEvent e) {
    had a local  String command = e.getActionCommand();
  That is, I    switch (command) {
        case "New" were named Foo.  -> {
            both of which  frame.setTitle("Untitled");
            remote branch,  textArea.setText("");
            path =  and a mapped   "";
        }
        case "Open" -> local branch  open();
        case "SaveAs" -> I had a  saveAs();
        case "Save" -> with lines.  save();
        case "Exit" -> display array  onQuit();
        case "Undo" -> it doesn't   undoManager.undo();
        case "Redo" is running but  -> undoManager.redo();
        case quiz.The program  "Copy" -> textArea.copy();
         file is named  case "Paste" -> textArea.paste();
    with it. My      case "Cut" -> textArea.cut();
    what is wrong      case "Small" ->  I don't know   textArea.setFont(new Font("", my code and  Font.PLAIN, 30));
        case "Medium" loop. Here is  -> textArea.setFont(new Font("", in a for  Font.PLAIN, 35));
        case "Large" to display it  -> textArea.setFont(new Font("", Then I want  Font.PLAIN, 40));
    }
}

private void into an array.  save() {
    if (path == "" || path == and save it  null) {
        saveAs();
    } else {
  a .txt file        saveWorker = new get lines from  SwingWorker<>() {
            I want to  @Override
            protected NullType by it   doInBackground() {
                try what they mean  {
                    if don't see exactly  (!path.endsWith(".txt")) {
              other. But I            FileWriter writer = new better than the  FileWriter(path + ".txt");
               one language is             want to stress  writer.write(textArea.getText());
        when people                   writer.close();
         the word 'expressiveness'              } else {
                    a lot of      FileWriter writer = new -loop. I see  FileWriter(path);
                       of the for   writer.write(textArea.getText());
      the next iteration                    writer.close();
       not move to               }

                } catch  get stuck and  (IOException e) {
                     it seems to  e.printStackTrace();
                }
  answered in time,                return null;
             if it's not  }
        };
        the program. And  saveWorker.execute();
    }
}

private will just stop  void saveAs() {

    saveAsWorker = new in time, it   SwingWorker<>() {
         if it's answered  @Override
        protected String . However instead  doInBackground() {
            the next iteration  JFileChooser chooser = new and continue onto  JFileChooser();
            int choice = print a message  chooser.showSaveDialog(frame);

         sleep), it will     String fileName = "Untitled";

       of the Thread.       if (choice == 1 second (duration  JFileChooser.APPROVE_OPTION) {
           number within        try {
                    File not enter a  file = chooser.getSelectedFile();
       the user does               path = file.toString();

   is that if                   if of the program  (!path.endsWith(".txt")) {
              So the purpose            FileWriter writer = new blade snip:  FileWriter(path + ".txt");
              . Here is              button onClick event  writer.write(textArea.getText());
       change the Add                   writer.close();
        I'd like to              } else {
                    from the controller,      FileWriter writer = new the returned result  FileWriter(path);
                        value. Based on   writer.write(textArea.getText());
      validates provided                    writer.close();
        a controller which                }

                    ajax callback to  StringBuilder builder = new  there is an  StringBuilder(path);
                     On form submit  fileName = in blade template.  builder.substring(builder.lastIndexOf("\\") additional Add button  + 1);
                } catch button and an  (IOException e) {
                    with a Submit  e.printStackTrace();
                }
  a simple form             }

            return me.I have   fileName;
        }

        @Override
  fix it for        protected void done() {
           should help and   try {
                my code someone  frame.setTitle(get() + ".txt");
         going wrong with     } catch (InterruptedException | were am i   ExecutionException exception) {
         _id,please          exception.printStackTrace();
     the first user         }
        }
    };

    will only echo  saveAsWorker.execute();

}

private void  my code it  open() {
     when i run  SwingWorker<List<String>, to 20,But  NullType> worker = new friend_id equal  SwingWorker<>() {
        id that their  @Override
        protected all the user_  List<String> doInBackground() {
   want to echo           JFileChooser chooser = new is that i   JFileChooser();
            int choice =  code,the problem  chooser.showOpenDialog(frame);

          am stuck with     String fileName = "";
            system,But now  path = "";
            if (choice == a friend_list  JFileChooser.APPROVE_OPTION) {
          am developing        File file =  them as such  chooser.getSelectedFile();
              unnecessary to store    StringBuilder stringBuilder = new numbers, it is  StringBuilder(file.toString());
         ask for sorted         fileName = assignment does not  stringBuilder.substring(stringBuilder.lastIndexOf("\\") that since the  + 1);
                path =  and I think  file.getPath();
            }

          using bubble sorting    ArrayList<String> lines = new I've looked into  ArrayList<>();

            try {
  a text file.                 FileReader fileReader = array read from  new FileReader(path);
                of a given  BufferedReader reader = new the highest number  BufferedReader(fileReader);

            function determine      String line;
                while to create a   ((line = reader.readLine()) != null)
    My assignment is                  lines.add(line);

       get the error:           fileReader.close();
             Server, since I      reader.close();

                in a Divio  lines.add(fileName);

            }  my Django project   catch (IOException e) {
                I can't deploy  e.printStackTrace();
            }

     to know why         return lines;
        }

        I would like  @Override
        protected void done()  like this  {
            try {
                is something  textArea.setText("");
                 i can think  List<String> lines = get();

      to powershell all            for (int i = 0; i <= Complete beginner  lines.size() - 2; i++)
                  Where-Object?    textArea.append(lines.get(i) + -Process to  "\n");

                output from Get  frame.setTitle(lines.get(lines.size() - by piping the  1));
            } catch using CPU > 1%  (InterruptedException | lists the processes  ExecutionException | How does one  IndexOutOfBoundsException exception) {
  and cgroups.                using namespaces  exception.printStackTrace();
            Linux kernel,  }
        }
    };

    done by the  worker.execute();
}

private void heavy lifting is  createMenuBar() {

    menuBar = new most of the  JMenuBar();

    fileMenu = new  it seems that  JMenu("File");
    editMenu = new learning docker and  JMenu("Edit");
    fontMenu = new I recently started  JMenu("Font");
    sizeMenu = new ,notation.  JMenu("Size");

    List<JMenu> my Big O   menus = Arrays.asList(fileMenu, that do to   editMenu, fontMenu, sizeMenu);
    them what would  menus.forEach(menu -> {
        through all of  menu.getPopupMenu().setBorder(null);
     it would run       menuBar.add(menu);
    });

     worst case scenario  //file

    newItem = new like this and  JMenuItem("New");
    in a row  newItem.addActionListener(this);
    I have 4  newItem.setActionCommand("New");
    (mn), but if  fileMenu.add(newItem);

    openItem = O is O  new JMenuItem("Open");
     m, the big  openItem.addActionListener(this);
    and that =  openItem.setActionCommand("Open");
    this = n  fileMenu.add(openItem);

    saveItem = that the if  new JMenuItem("Save");
     is. I know  saveItem.addActionListener(this);
    notation of this  saveItem.setActionCommand("Save");
     the Big O   fileMenu.add(saveItem);

    saveAsItem  figure out what  = new JMenuItem("SaveAs");
    I'm trying to  saveAsItem.addActionListener(this);
     wouldn't work.   saveAsItem.setActionCommand("SaveAs");
  them codes    fileMenu.add(saveAsItem);

    switch case but  exitItem = new JMenuItem("Exit");
    breaks and a  exitItem.addActionListener(this);
    I've tried using  exitItem.setActionCommand("Exit");
    been printed.  fileMenu.add(exitItem);

    //edit

    the vowels have  undoItem = new JMenuItem("Undo");
    constant after all  undoItem.addActionListener(this);
    same for each  undoItem.setActionCommand("Undo");
    . Then do the   editMenu.add(undoItem);

    redoItem = order they appear  new JMenuItem("Redo");
    line in the   redoItem.addActionListener(this);
    on a new  redoItem.setActionCommand("Redo");
    from a word  editMenu.add(redoItem);

    copyItem =  print any vowels  new JMenuItem("Copy");
    arrayTrying to  copyItem.addActionListener(this);
    through the firebase  copyItem.setActionCommand("Copy");
    loop which does  editMenu.add(copyItem);

    pasteItem = This is the  new JMenuItem("Paste");
    it is undefined.  pasteItem.addActionListener(this);
    or value.uid   pasteItem.setActionCommand("Paste");
     use value.key  editMenu.add(pasteItem);

    cutItem = but if I  new JMenuItem("Cut");
    get the key  cutItem.addActionListener(this);
     I need to  cutItem.setActionCommand("Cut");
    when selected and  editMenu.add(cutItem);

    //font



   to the function   //size

    smallItem = new is passed through  JMenuItem("Small");
    of the object   smallItem.addActionListener(this);
    A single instance  smallItem.setActionCommand("Small");
     through?  sizeMenu.add(smallItem);

    mediumItem the object passed  = new JMenuItem("Medium");
    key value of   mediumItem.addActionListener(this);
     I get the  mediumItem.setActionCommand("Medium");
  through, how do    sizeMenu.add(mediumItem);

    list is passed  largeItem = new JMenuItem("Large");
    object in the  largeItem.addActionListener(this);
     and a single  largeItem.setActionCommand("Large");
    is looped through  sizeMenu.add(largeItem);

    FirebaseListObservable which  frame.setJMenuBar(menuBar);
}

}

Total Answers 0

Top rated topics

Classifying pixels based on colour using keras

Pyparsing: Trailing whitespace is not matched but still included for endloc calculation

Extend functionality of dependent classes in a module in python

QListWidget don't show the selected row

Spring boot request data from multiple endpoints

How to change the graph colour based on the different values

Complicated plots faceting

Is Firestore onCreate trigger contains the latest data or only the data submitted during creation?

How to connect to redis cluster via ApScheduler RedisJobStore

Copy last x values from a filtered range

How to recive multiply urls from telegram bot using aiogram

Integrate bitbucket with Tekton as k8s basic-auth

.get function Data to Panda Dataframe gives TypeError: 'type' object is not subscriptable

How to return text as json in exception handler

SQLite Argument out of range

Getting an issue in applying margin on the runtime using angular

SSH2 nodejs TypeError: Cannot read property 'PROTOCOL_ERROR' of undefined

Calculate folder size with multithreading

TypeError: Cannot read properties of undefined (reading 'map'

GetPixel Function Doesn't Work in Qt C++ LNK2019 undefined reference to __imp_GetPixel

Can i make post request using url like "/box?cnb=s3" in laravel route?

How to replace old text with new one between some specific lines in python?

Converting null literal for Console.ReadLine() for string input

How to get a list of shared mailboxes for a user in ews-java-api?

Extract Wikipedia Data From XML Data dumps

Run shell from python to open a file

Calculating column means based on values in other columns in pandas

Is there a way to extract a comment out of a C string?

Is it possible to not use cardinality constraint to generate solution candidates in clingo?

Unknown MySQL server host 'loclhost' (-2) in popsql

Invalid JSON text but it seems that it is okay

How to join with complecated condition in redshift

Crictl - How to pull from private repository?

Converting a Seq[Int] to a tuple with predetermined size, in Scala

How to plot imshow legend based on colormap?

Days between orderdates per Customer and first order value

&gt; No signature of method

Show data in dropdown based on first dropdown selection (react/typescript)

Drag and drop ranking function in Laravel form

Reject approved update in Google Play Console's Managed Publishing

SQL, during query create new column based on data conditions

How to get the value of a textarea element Java?

Preventing exceeding a heap when reading a large text file

How to remove ApiUtil.java from openApi geneate task with openapi-generator-gradle-plugin:4.3.0

List index out of range .what to do?

ToContain() with or options

MYSQL how to check if there are multiple rows other than value x

How to download pdf file from local app storage to phone storage in react native using expo

What is the proper term for recursively processing or "spidering" a JavaScript object with unknown keys?

TypeError: _this.services.languageUtils.isWhitelisted is not a function

Top