Итак, я все еще новичок в java, и мой проект должен состоять из нескольких дней , и я все еще застрял в этих двух проблемах i ' v много искал и читал, что он должен работать , но это не будет У меня есть изображение в кадре и несколько кнопок, которые я хочу, когда нажата кнопка, изображение изменится.изменение изображения другим при нажатии кнопки и изменение jtextarea при выборе радиообмена
общественного класс животные расширяют JFrame реализует ActionListener {
static JPanel buttons =new JPanel();
static JLabel intro =new JLabel("Guess what the animal that makes the noise and press to find out!");
Icon birdy=new ImageIcon(getClass().getResource("bird.png"));
JLabel bird=new JLabel(birdy,SwingConstants.CENTER);
Icon eleph=new ImageIcon(getClass().getResource("elephant.jpg"));
JLabel elephant=new JLabel(eleph,SwingConstants.CENTER);
Icon tig=new ImageIcon(getClass().getResource("tiger.png"));
JLabel tiger=new JLabel(tig,SwingConstants.CENTER);
Icon wol=new ImageIcon(getClass().getResource("wolf.png"));
JLabel wolf=new JLabel(wol,SwingConstants.CENTER);
Icon caat=new ImageIcon(getClass().getResource("caat.jpg"));
JLabel cat=new JLabel(caat,SwingConstants.CENTER);
Icon coww=new ImageIcon(getClass().getResource("cow.png"));
JLabel cow=new JLabel(coww,SwingConstants.CENTER);
Icon dogy=new ImageIcon(getClass().getResource("dog.png"));
JLabel dog=new JLabel(dogy,SwingConstants.CENTER);
Icon ducky=new ImageIcon(getClass().getResource("duck.jpg"));
JLabel duck=new JLabel(ducky,SwingConstants.CENTER);
Icon horsey=new ImageIcon(getClass().getResource("horse.png"));
JLabel horse=new JLabel(horsey,SwingConstants.CENTER);
Icon moonkey=new ImageIcon(getClass().getResource("monkey.png"));
JLabel monkey=new JLabel(moonkey,SwingConstants.CENTER);
Icon poke=new ImageIcon(getClass().getResource("pokemons.jpg"));
JLabel pokemon=new JLabel(poke,SwingConstants.CENTER);
Icon pika=new ImageIcon(getClass().getResource("pikachu.png"));
JLabel pikachu=new JLabel(pika,SwingConstants.CENTER);
Icon chari=new ImageIcon(getClass().getResource("charizard.png"));
JLabel charizard=new JLabel(chari,SwingConstants.CENTER);
Icon pic=new ImageIcon();
JLabel picture=new JLabel(pic,SwingConstants.CENTER);
static JButton catb=new JButton("Meow~~");
static JButton dogb=new JButton("Woof Woof~~");
static JButton horseb=new JButton("Hihi-n~~");
static JButton duckb=new JButton("Quack~~");
static JButton monkeyb=new JButton("Ki-Ki~~");
static JButton elephantb=new JButton("Pao--n~~");
static JButton cowb=new JButton("Moo~~");
static JButton birdb=new JButton("pichu pichu~~");
static JButton wolfb=new JButton("Awwooo~~");
static JButton tigerb=new JButton("Rawr~~");
public void animals()
{
animals add =new animals();
add.setLayout(new FlowLayout());
add.setVisible(true);
add.setTitle("Letters");
add.setSize(500,550);
add.getContentPane().setBackground(Color.WHITE);
add.add(intro);
add.add(pokemon);
buttons.setBackground(Color.WHITE);
buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
buttons.setLayout(new GridLayout(5, 5));
add.add(catb);
buttons.add(horseb);
buttons.add(duckb);
buttons.add(elephantb);
buttons.add(dogb);
buttons.add(birdb);
buttons.add(tigerb);
buttons.add(monkeyb);
buttons.add(wolfb);
buttons.add(cowb);
buttons.add(pikachu);
buttons.add(charizard);
add.add(picture);
add.add(buttons);
catb.addActionListener(add);
horseb.addActionListener(add);
elephantb.addActionListener(add);
duckb.addActionListener(add);
dogb.addActionListener(add);
birdb.addActionListener(add);
tigerb.addActionListener(add);
monkeyb.addActionListener(add);
wolfb.addActionListener(add);
cowb.addActionListener(add);
}
@Override
public void actionPerformed(ActionEvent ae) {
if(ae.getSource()==catb)
{
picture.setIcon(caat);
}
if(ae.getSource()==horseb)
{
pokemon.setIcon(horsey);
}
}
}
другой вещью является радиокнопкой я хочу, когда она нажата, цвет текста области изменится еще раз перечитал он должен работать, но это не
public class colors extends JFrame implements ItemListener {
JPanel pc=new JPanel();
JRadioButton red=new JRadioButton("Red");
JRadioButton blue=new JRadioButton("Blue");
JRadioButton black=new JRadioButton("Black");
JRadioButton pink=new JRadioButton("Pink");
JRadioButton yellow=new JRadioButton("Yellow");
JRadioButton green=new JRadioButton("Green");
JRadioButton orange=new JRadioButton("Orange");
Icon meow=new ImageIcon(getClass().getResource("meowtwo.png"));
JLabel meowtwo=new JLabel(meow,SwingConstants.CENTER);
JLabel hi=new JLabel("explore the colors !!!");
JTextArea color=new JTextArea(20,40);
static ButtonGroup col=new ButtonGroup();
public void colors()
{
colors add =new colors();
add.setLayout(new FlowLayout());
add.setVisible(true);
add.setTitle("Letters");
add.setSize(500,550);
add.getContentPane().setBackground(Color.DARK_GRAY);
pc.setBackground(Color.GRAY);
hi.setFont(new Font("Serif",Font.BOLD,40));
color.setEditable(false);
col.add(red);
col.add(blue);
col.add(black);
col.add(pink);
col.add(yellow);
col.add(green);
col.add(orange);
color.setBackground(color.getBackground());
pc.add(hi);
pc.add(meowtwo);
add.add(pc);
add.add(red);
add.add(blue);
add.add(black);
add.add(pink);
add.add(yellow);
add.add(green);
add.add(orange);
add.add(color);
red.addItemListener(add);
blue.addItemListener(add);
black.addItemListener(add);
pink.addItemListener(add);
yellow.addItemListener(add);
green.addItemListener(add);
orange.addItemListener(add);
}
@Override
public void itemStateChanged(ItemEvent ie) {
colors add=new colors();
if(red.isSelected())
{
add.getContentPane().setBackground(Color.yellow);
}
else
color.setBackground(Color.yellow);
}
}
я знаю, что мой код не самый лучший, но снова я все еще учусь , пожалуйста, помогите этой бедной Борясь студенту
oh man !! Я не могу поверить, что забыл об этом! ты действительно спас меня, большое спасибо :))))))))) –