Need Urgent Java Coding help

Zeus

Well-known member
  • Sep 14, 2007
    20,327
    1,957
    113
    Kalutara
    rochel1977 said:
    Kawda java gena danne?

    mamm coding ekak liwwa. eke mata one quote karapu text ekath ekkama image ekak display karanda. any help??

    I'll try machan but im amateur too
    Lets see we can help it :yes:
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    plz put ur code in here so we cn look in to that.... and plz wrap it within
    Code:
     blocks
    "[ code ] [ / code ]"
    without spaces and quotes :P
     

    rochel1977

    Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    Zeus said:
    I'll try machan but im amateur too
    Lets see we can help it :yes:

    thx malli. mata podi coding ekak thamai one. ee kiyane code eka liyala iwarai. radiobutton eka click karadi mata text ekath wadenda one image ekath ekka. menna code eka

    Code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.ImageIcon;
    
    
    public class Quote extends JFrame
    {
    	public static void main(String arg[])
    	{
    		final JLabel quote = new JLabel();		
    		JPanel pquote = new JPanel();
    		JPanel pradio = new JPanel();
    		
    		quote.setFont(new Font("Helvetica", Font.PLAIN, 24));
    		
    		final ButtonGroup group = new ButtonGroup();
    
    		JRadioButton mahatir = new JRadioButton("Dr.Mahatir",true);
    		JRadioButton paklah = new JRadioButton("Pak Lah",false);
    		JRadioButton pckang = new JRadioButton("Phua Chu Kang",false);
    		
    		pquote.setBackground(Color.green);
    		pradio.setBackground(Color.yellow);
    
    		group.add(mahatir);
    		group.add(paklah);
    		group.add(pckang);
    
    		pradio.add(mahatir);
    		pradio.add(paklah);
    		pradio.add(pckang);
    
    		JCheckBox bold = new JCheckBox("BOLD");
    		JCheckBox italic = new JCheckBox("ITALIC");
    		
    
    
        		class VoteItemListener implements ItemListener {
          			public void itemStateChanged(ItemEvent ex) {
            			String item = ((AbstractButton) ex.getItemSelectable()).getActionCommand();
            			boolean selected = (ex.getStateChange() == ItemEvent.SELECTED);
            			if(selected)
    				{
    					if(item.equals("Dr.Mahatir"))
    						quote.setIcon(new ImageIcon(getClass().getResource("/1.jpg")));								
    					else if(item.equals("Pak Lah"))
    						quote.setIcon(new ImageIcon(getClass().getResource("/2.jpg")));		
    					else if(item.equals("Phua Chu Kang"))
    						quote.setIcon(new ImageIcon(getClass().getResource("/3.jpg")));		
    				}
          			}
        		}
    
    		ItemListener itemListener = new ItemListener() {
    		      public void itemStateChanged(ItemEvent itemEvent) {
    		      AbstractButton abstractButton = (AbstractButton)itemEvent.getSource();
            	      int state = itemEvent.getStateChange();
    		      if (state == ItemEvent.SELECTED) {
    			     quote.setFont(quote.getFont().deriveFont(quote.getFont().getStyle()+Font.ITALIC));
    		      }
    		      else
    			     quote.setFont(quote.getFont().deriveFont(Font.PLAIN));
    	  	     }
    	      };
    		ItemListener itemListenerBold = new ItemListener() 
    			{
    		      public void itemStateChanged(ItemEvent itemEvent) 
    		      	{
    		      AbstractButton abstractButton = (AbstractButton)itemEvent.getSource();
            	      int state = itemEvent.getStateChange();
    		      if (state == ItemEvent.SELECTED) 
    		      	{
    			     quote.setFont(quote.getFont().deriveFont(quote.getFont().getStyle()+Font.BOLD));
    		      	}
    		      else
    			     quote.setFont(quote.getFont().deriveFont(Font.PLAIN));
    	  	     }
    	      };
                    bold.addItemListener(itemListenerBold);
    		italic.addItemListener(itemListener);
    
    		pquote.add(quote);
    		pquote.add(bold);
    		pquote.add(italic);		
    
    
    		ItemListener al = new VoteItemListener();
    		mahatir.addItemListener(al);		
    		paklah.addItemListener(al);
    		pckang.addItemListener(al);
    
    		JFrame frame = new JFrame("Quote");
    		frame.setLayout(new BorderLayout());
    		
    		
    
    		frame.add(pquote, BorderLayout.CENTER);
    		frame.add(pradio, BorderLayout.PAGE_END);
    		frame.setSize(500, 600);
        		frame.setVisible(true);
    	    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	    	
         	}
    }
     

    Zeus

    Well-known member
  • Sep 14, 2007
    20,327
    1,957
    113
    Kalutara
    amila325 said:
    plz put ur code in here so we cn look in to that.... and plz wrap it within
    Code:
     blocks
    "[ code ] [ / code ]"
    without spaces and quotes :P[/quote] 
    [SIZE=4][COLOR=Green]
    Seems like "keruma" just showed up :D[/COLOR][/SIZE]
     

    Zeus

    Well-known member
  • Sep 14, 2007
    20,327
    1,957
    113
    Kalutara
    rochel1977 said:
    thx malli. mata podi coding ekak thamai one. ee kiyane code eka liyala iwarai. radiobutton eka click karadi mata text ekath wadenda one image ekath ekka. menna code eka

    MEnna mehema siddiyak have
    Oya NetBeans ne use karanna atte ?
    NetBenas valin genarated codeuth oya meke dalada thiyenne ??
    Anna evanam api danne na
    Oya liyapuva vitarak dunnanam tavath lesiyi:yes:

    And balanna referance ehama harida kiyala
    :yes:
     

    rochel1977

    Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    amila325 said:
    plz put ur code in here so we cn look in to that.... and plz wrap it within
    Code:
     blocks
    "[ code ] [ / code ]"
    without spaces and quotes :P[/QUOTE]
    
    ela i posted it amila. i just want these text to appear also once i click the radio buttons
    
    [code]if(item.equals("Dr.Mahatir"))
    quote.setText("Malaysian Boleh!");
    else if(item.equals("Pak Lah"))
    quote.setText("Work with me: )");
    else if(item.equals("Phua Chu Kang"))
    quote.setText("Don't play-play!");
     

    rochel1977

    Well-known member
  • May 15, 2006
    11,466
    2,673
    113
    AKL, NZ and Kandy
    Zeus said:
    MEnna mehema siddiyak have
    Oya NetBeans ne use karanna atte ?
    NetBenas valin genarated codeuth oya meke dalada thiyenne ??
    Anna evanam api danne na
    Oya liyapuva vitarak dunnanam tavath lesiyi:yes:

    And balanna referance ehama harida kiyala
    :yes:

    ne malaya net beans neme. mama use karanne JCreator
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    Zeus said:
    MEnna mehema siddiyak have
    Oya NetBeans ne use karanna atte ?
    NetBenas valin genarated codeuth oya meke dalada thiyenne ??
    Anna evanam api danne na
    Oya liyapuva vitarak dunnanam tavath lesiyi:yes:

    And balanna referance ehama harida kiyala
    :yes:
    this is not a netbeans coding :)... dnt wory :) :)
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    rochel1977 said:
    ela i posted it amila. i just want these text to appear also once i click the radio buttons

    Code:
    if(item.equals("Dr.Mahatir"))
    quote.setText("Malaysian Boleh!");
    else if(item.equals("Pak Lah"))
    quote.setText("Work with me: )");
    else if(item.equals("Phua Chu Kang"))
    quote.setText("Don't play-play!");
    easiest way is to add a label and add the picture there :) :)......
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    Zeus said:
    So u r the only player in this match
    Keep up man :D
    hihi thanx man....

    rochel there is another way u will hv to override da paint method in JPanel class inside a class of your own...

    Code:
    class MyPanel extends JPanel {
    
     private Image img;
    
     public MyPanel(Image img) {
       this.img = img;
       //do what ever u need to do in the jpanel layouts and everything
     }
    
      public void paintComponent(Graphics g) {
        g.drawImage(img, 0, 0, null);
      }
    }
    after this you can use this class as a customized JPanel
     
    Last edited: