calling function from other java file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eyeofsoul
    New Member
    • Sep 2007
    • 31

    #1

    calling function from other java file

    hello..i am having a difficulties in calling the function in other file.

    for example..this is the file that use xxx.java;
    Code:
    package netbean5test;
    
    import netbean5test.xxx;
    
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*; //button
    import java.io.*;
    
    public class testpopup extends JFrame implements ActionListener{
        
        private JButton satu = new JButton("SATU");
        private JButton dua = new JButton("DUA");
    
        
        public testpopup(){
            
            setBackground(Color.ORANGE);
            JPanel one = new JPanel();
            Container c = getContentPane();
            c.setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
           
            c.add(satu);
            c.add(dua);
          
            
            satu.addActionListener(this);
            dua.addActionListener(this);  
           
            
        }
        
        public void actionPerformed(ActionEvent e){
            
            if(e.getSource()==satu){
           
                JOptionPane x = new JOptionPane();
                x.setMessageType(JOptionPane.ERROR_MESSAGE);
                x.showMessageDialog(null, "Ini adalah popup..");
            }
            
            else if(e.getSource()==dua){
                
            }
            
        }
        
        public static void main(String[] args){
            testpopup kawasan = new testpopup();
            kawasan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            kawasan.setTitle("POPUP!!");
            kawasan.setSize(400,400);
            kawasan.setVisible(true);
        }
    }
    how i can display the xxx.java program when i click the second button?
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    what exactly is it you want to happend when you click the second button (In words) ?
    Not quite sure I understood you question.

    Give me some more information and I'll do my best to help.

    Comment

    • epots9
      Recognized Expert Top Contributor
      • May 2007
      • 1352

      #3
      Originally posted by eyeofsoul
      hello..i am having a difficulties in calling the function in other file.

      for example..this is the file that use xxx.java;
      Code:
      package netbean5test;
      
      import netbean5test.xxx;
      
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*; //button
      import java.io.*;
      
      public class testpopup extends JFrame implements ActionListener{
          
          private JButton satu = new JButton("SATU");
          private JButton dua = new JButton("DUA");
      
          
          public testpopup(){
              
              setBackground(Color.ORANGE);
              JPanel one = new JPanel();
              Container c = getContentPane();
              c.setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
             
              c.add(satu);
              c.add(dua);
            
              
              satu.addActionListener(this);
              dua.addActionListener(this);  
             
              
          }
          
          public void actionPerformed(ActionEvent e){
              
              if(e.getSource()==satu){
             
                  JOptionPane x = new JOptionPane();
                  x.setMessageType(JOptionPane.ERROR_MESSAGE);
                  x.showMessageDialog(null, "Ini adalah popup..");
              }
              
              else if(e.getSource()==dua){
                  
              }
              
          }
          
          public static void main(String[] args){
              testpopup kawasan = new testpopup();
              kawasan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              kawasan.setTitle("POPUP!!");
              kawasan.setSize(400,400);
              kawasan.setVisible(true);
          }
      }
      how i can display the xxx.java program when i click the second button?
      if your calling one method form one file to another (one class to another), if the method in question is static then the method call would be prefixed with the class name, if it is a non-static method you will have to create an object of the second class and prefix the method class with the object.

      Comment

      Working...