Results 1 to 4 of 4
  1. #1
    reeveliew is offline Member
    Join Date
    May 2010
    Posts
    13
    Rep Power
    0

    Default can i combine this 2 code into one?

    Detele Code
    import java.io.File;

    public class Main {

    public static void main(String[] args) throws Exception {
    File file = new File("C:/Demo.txt");
    System.out.println(file.delete());
    }
    }


    Input Code
    import javax.swing.*;
    import java.awt.event.*;

    public class ShowInputDialog{
    public static void main(String[] args){
    JFrame frame = new JFrame("Input Dialog Box Frame");
    JButton button = new JButton("Show Input Dialog Box");
    button.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent ae){
    String str = JOptionPane.showInputDialog(null, "Enter the file name you wan to delete : ",
    "test", 1);
    if(str != null)
    JOptionPane.showMessageDialog(null, "You entered the file name : " + str,
    "test", 1);
    else
    JOptionPane.showMessageDialog(null, "You pressed cancel button.",
    "test", 1);
    }
    });
    JPanel panel = new JPanel();
    panel.add(button);
    frame.add(panel);
    frame.setSize(400, 400);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);
    }
    }

  2. #2
    manward is offline Member
    Join Date
    May 2010
    Posts
    1
    Rep Power
    0

    Default

    yes ! you can.i combine these classes into one class.and use JFileChooser for

    selecting file from hard.

    Java Code:
    
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    
    public class ShowInputDialog {
    
    
        public static void delete(File fileName){
    
    
            fileName.delete();
    
         JOptionPane.showMessageDialog(null, "your file Deleted !","File Status", 1);
    
    
        }
    
    
    
        public static void main(String[] args) {
            
            JFrame frame = new JFrame("Input Dialog Box Frame");
            
            JButton button = new JButton("Show Input Dialog Box");
            
            button.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent ae) {
    
    
                    JFileChooser fc=new JFileChooser();
    
                    int re=fc.showOpenDialog(fc);
    
                    if(re==JFileChooser.APPROVE_OPTION){
    
                        File file=fc.getSelectedFile();
    
                        delete(file);
    
    
                    }
                    
    
    
    
                }
            });
            JPanel panel = new JPanel();
            panel.add(button);
            frame.add(panel);
            frame.setSize(400, 400);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
             frame.setVisible(true);
        }
    }

  3. #3
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    6

    Default

    might i add, this tutorial if you want to look at what its called.

    look here

    Nested Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    @OP, please use code tags next time when you are posting here again in the forum. Unformated codes are really hard to read. If you don't know how to do it, please check on my forum signature, you can find a link to relevant explanation in details. :)

Similar Threads

  1. Replies: 0
    Last Post: 04-15-2010, 10:06 AM
  2. How can I do this? Combine variable.
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 01-14-2009, 05:44 PM
  3. [SOLVED] How do I combine two variables?
    By bobleny in forum New To Java
    Replies: 12
    Last Post: 07-08-2008, 03:15 PM
  4. How to combine mysql and java?
    By sandeeprao.techno in forum Advanced Java
    Replies: 1
    Last Post: 05-21-2008, 04:41 AM
  5. Combine package of(jdk,eclipse and tomcat)
    By joseph in forum Eclipse
    Replies: 0
    Last Post: 04-07-2008, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •