Help with adding border colors

Discussion in 'Programming General' started by oxygnick, Dec 18, 2008.

Help with adding border colors
  1. Unread #1 - Dec 18, 2008 at 3:19 AM
  2. oxygnick
    Referrals:
    0

    oxygnick Guest

    Help with adding border colors

    So I'm taking a Computer Programming class for College, and I have this packet due tomorrow. I am stuck on this one problem. I am unsure of how to add border colors around the window. Would anyone mind pointing me in the right direction? Here is my coding if it helps at all. Thanks

    //references illustrates the List and TextArea
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.Applet;
    import javax.swing.*;//for JFrame and JPanel
    public class ListText extends Applet implements ActionListener, ItemListener
    {
    private List animals = new List(3,true);
    private List things = new List(4);
    private TextArea text = new TextArea(4,20);
    private Button choose = new Button("Choose Animals");
    public void init()
    {

    animals.add("cow");
    animals.add("horse");
    animals.add("pig");
    animals.add("elephant");
    animals.add("flea");
    animals.add("duck");
    animals.add("chicken");
    animals.add("dog");
    add(animals);
    things.add("moon");
    things.add("barn");
    things.add("cliff");
    things.add("brook");
    things.add("pond");
    things.add("coop");
    things.add("yard");
    add(things);
    add(text);
    add(choose);
    choose.addActionListener(this);
    things.addItemListener(this);

    }
    public String buildString(String[] animals, String thing)
    {
    StringBuffer message = new StringBuffer(50);
    message.append("The ");
    int length = animals.length;
    switch(length)
    {
    case 0: message.append("??");
    break;
    case 1: message.append(animals[0]);
    break;
    case 2: message.append(animals[0]);
    message.append(" and ");
    message.append(animals[1]);
    break;
    default:
    for(int i = 0; i < length-1; i++)
    {
    message.append(animals);
    message.append(", ");

    }
    message.append("and ");
    message.append(animals[length-1]);
    }
    message.append(" jumped\n over the ");
    message.append(thing);
    return message.toString();
    }
    public void actionPerformed(ActionEvent event)
    {
    Object source = event.getSource();
    if (source==choose)
    text.setText
    (buildString(animals.getSelectedItems(), things.getSelectedItem()));
    }
    public void itemStateChanged(ItemEvent e)
    {
    Object source = e.getSource();
    if (source==things)
    text.setText("You selected " + things.getSelectedItem());
    }
    }
     
  3. Unread #2 - Dec 18, 2008 at 4:52 PM
  4. Zyloch
    Joined:
    Apr 21, 2005
    Posts:
    63
    Referrals:
    0
    Sythe Gold:
    0

    Zyloch Member

    Help with adding border colors

    There may be different ways to do this. One way is to use the JApplet class instead of the Applet class, set its background color, and return insets. If your applet is sized correctly in the HTML, you can also try something like:

    JPanel contentPanel = new JPanel();
    contentPanel.setBorder(BorderFactory.createLineBorder(Color.red, 10));

    Then, instead of adding your components to the Applet, add them to the JPanel:

    contentPanel.add(animals);

    Finally, add the panel itself:

    add(contentPanel);
     
< I need some help... | I needs help x.x >

Users viewing this thread
1 guest


 
 
Adblock breaks this site