java help (process complete but no output)

  • frezasaga
  • Beginner
  • Beginner
  • frezasaga
  • Posts: 41

Post 3+ Months Ago

i just playing a java script i combined a simple program but when i done it complete process no output i mean there is no output to show.........where i missing......

Code: [ Select ]
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.color.*;
public class copro2 extends JFrame implements ActionListener
{
    public JButton red;
    public JButton blue;
    public copro2 (String title)
        {
            JFrame x = new JFrame("Layouts");
            x.setSize(500,500);
            x.getContentPane().setLayout(new BorderLayout());
            
            
            JLabel lab;
            lab = new JLabel("COLOR");
            lab.setForeground(Color.red);
            
            Container a = new Container();
            a.setLayout(new FlowLayout());
            a.add(lab);
            
            JButton black = new JButton ("BLACK");
            black.setBackground(Color.black);
            JButton white = new JButton ("WHITE");
            white.setBackground(Color.white);
            
            
            Container b = new Container();
            b.setLayout(new FlowLayout());
            b.add(black);
            b.add(white);
            
            
            JButton red = new JButton ("RED");
            red.setBackground(Color.red);
            red.addActionListener(this);
            JButton blue = new JButton ("BLUE");
            blue.setBackground(Color.blue);
            blue.addActionListener(this);
            JButton green = new JButton ("GREEN");
            green.setBackground(Color.green);
            JButton yellow = new JButton ("YELLOW");
            yellow.setBackground(Color.yellow);
            
            Container c = new Container();
            c.setLayout(new GridLayout(5,1));
            c.add(red);
            c.add(blue);
            c.add(green);
            c.add(yellow);
                        
            JButton cyan = new JButton ("CYAN");
            cyan.setBackground(Color.cyan);
            JButton magenta = new JButton ("MAGENTA");
            magenta.setBackground(Color.magenta);
            JButton gray = new JButton ("GRAY");
            gray.setBackground(Color.gray);
            JButton pink = new JButton ("PINK");
            pink.setBackground(Color.pink);
            
            Container d = new Container();
            d.setLayout(new GridLayout(5,1));
            d.add(cyan);
            d.add(magenta);
            d.add(gray);
            d.add(pink);
    
            
            
            x.getContentPane().add(a, BorderLayout.NORTH);
            x.getContentPane().add(b, BorderLayout.SOUTH);
            x.getContentPane().add(c, BorderLayout.WEST);
            x.getContentPane().add(d, BorderLayout.EAST);
            x.setVisible(true);
            x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            
            
        getContentPane().setLayout(new FlowLayout(1));
        getContentPane().add(red);
        getContentPane().add(blue);
        /* setVisible(true); */
            
            
        }
        public void actionPerformed (ActionEvent e){
        if (e.getSource()== red)
            getContentPane().setBackground(Color.blue);
            
         if (e.getSource () == blue){
            getContentPane() .setBackground(Color.red);
                
            }
    }
    public static void main (String [] args){
        
    }
        
}        
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. import java.awt.color.*;
  5. public class copro2 extends JFrame implements ActionListener
  6. {
  7.     public JButton red;
  8.     public JButton blue;
  9.     public copro2 (String title)
  10.         {
  11.             JFrame x = new JFrame("Layouts");
  12.             x.setSize(500,500);
  13.             x.getContentPane().setLayout(new BorderLayout());
  14.             
  15.             
  16.             JLabel lab;
  17.             lab = new JLabel("COLOR");
  18.             lab.setForeground(Color.red);
  19.             
  20.             Container a = new Container();
  21.             a.setLayout(new FlowLayout());
  22.             a.add(lab);
  23.             
  24.             JButton black = new JButton ("BLACK");
  25.             black.setBackground(Color.black);
  26.             JButton white = new JButton ("WHITE");
  27.             white.setBackground(Color.white);
  28.             
  29.             
  30.             Container b = new Container();
  31.             b.setLayout(new FlowLayout());
  32.             b.add(black);
  33.             b.add(white);
  34.             
  35.             
  36.             JButton red = new JButton ("RED");
  37.             red.setBackground(Color.red);
  38.             red.addActionListener(this);
  39.             JButton blue = new JButton ("BLUE");
  40.             blue.setBackground(Color.blue);
  41.             blue.addActionListener(this);
  42.             JButton green = new JButton ("GREEN");
  43.             green.setBackground(Color.green);
  44.             JButton yellow = new JButton ("YELLOW");
  45.             yellow.setBackground(Color.yellow);
  46.             
  47.             Container c = new Container();
  48.             c.setLayout(new GridLayout(5,1));
  49.             c.add(red);
  50.             c.add(blue);
  51.             c.add(green);
  52.             c.add(yellow);
  53.                         
  54.             JButton cyan = new JButton ("CYAN");
  55.             cyan.setBackground(Color.cyan);
  56.             JButton magenta = new JButton ("MAGENTA");
  57.             magenta.setBackground(Color.magenta);
  58.             JButton gray = new JButton ("GRAY");
  59.             gray.setBackground(Color.gray);
  60.             JButton pink = new JButton ("PINK");
  61.             pink.setBackground(Color.pink);
  62.             
  63.             Container d = new Container();
  64.             d.setLayout(new GridLayout(5,1));
  65.             d.add(cyan);
  66.             d.add(magenta);
  67.             d.add(gray);
  68.             d.add(pink);
  69.     
  70.             
  71.             
  72.             x.getContentPane().add(a, BorderLayout.NORTH);
  73.             x.getContentPane().add(b, BorderLayout.SOUTH);
  74.             x.getContentPane().add(c, BorderLayout.WEST);
  75.             x.getContentPane().add(d, BorderLayout.EAST);
  76.             x.setVisible(true);
  77.             x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  78.             
  79.             
  80.         getContentPane().setLayout(new FlowLayout(1));
  81.         getContentPane().add(red);
  82.         getContentPane().add(blue);
  83.         /* setVisible(true); */
  84.             
  85.             
  86.         }
  87.         public void actionPerformed (ActionEvent e){
  88.         if (e.getSource()== red)
  89.             getContentPane().setBackground(Color.blue);
  90.             
  91.          if (e.getSource () == blue){
  92.             getContentPane() .setBackground(Color.red);
  93.                 
  94.             }
  95.     }
  96.     public static void main (String [] args){
  97.         
  98.     }
  99.         
  100. }        
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

You're not doing anything in your main() method, so nothing happens:

JAVA Code: [ Select ]
public static void main (String [] args){
       
}
  1. public static void main (String [] args){
  2.        
  3. }
  • frezasaga
  • Beginner
  • Beginner
  • frezasaga
  • Posts: 41

Post 3+ Months Ago

what do u mean doing anything in my main method.......
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6251
  • Loc: Seattle, WA

Post 3+ Months Ago

main() is the entry point to every Java program. If you don't actually initialize and run some code, nothing is going to happen; the program will simply exit immediately.

It looks like you need to learn basic programming concepts before you start piecing together other people's code.
  • frezasaga
  • Beginner
  • Beginner
  • frezasaga
  • Posts: 41

Post 3+ Months Ago

got ur point........already figure it out........

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.