Help Me Here Dude Please Graphical User Interface

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.border.Border;

public class JokeList extends JFrame implements ActionListener{

	
	private DefaultListModel listModel = new DefaultListModel();
	
	private JButton addbtn = new JButton("ADD JOKE");
	
	private JLabel backgroundlbl = new JLabel();
	
	private JTextField addtf = new JTextField(" ");
	
	private Border firstBorder = BorderFactory.createRaisedBevelBorder();
	
	private ImageIcon background = new ImageIcon("image/a.jpg");
	private ImageIcon titleIcon = new ImageIcon("image/b.jpg");


	public JokeList(){
		
		super("Joke List");
		JList list = new JList(listModel);
		setLayout(null);
		setIconImage(titleIcon.getImage());
		
		
		
		addbtn.setBounds(10 , 50 , 120 , 40);
		addtf.setBounds(135 , 50 , 240 , 40);
		list.setBounds(80 , 100 , 240 , 300);
		backgroundlbl.setBounds(0 , 0 , 400 , 500);
		
		add(addbtn);
		add(addtf);
		add(backgroundlbl);
		add(list);
		
		addbtn.setBorder(firstBorder);
		addtf.setBorder(firstBorder);
		
		backgroundlbl.setIcon(background);
		
		list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		list.setLayoutOrientation(JList.VERTICAL_WRAP);
		list.setVisibleRowCount(-1);
		
		addbtn.addActionListener(this);
		
		
	
	}
	
	public void actionPerformed(ActionEvent event){
	
		Object source = event.getSource();
		
		if(source == addbtn){
		
			listModel.addElement(addtf.getText());
			addtf.setText(" ");
			
		
		}
	
	
	}


	public static void main(String[] args){
	
		JokeList jokeListObject = new JokeList();
		
		jokeListObject.setSize(400,500);
		jokeListObject.setVisible(true);
		jokeListObject.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jokeListObject.setResizable(false);
		jokeListObject.setLocationRelativeTo(null);
		
		
	
	
	}
	
}


my problem is how i can remove joke , i have to add another button for remove joke . and how i gonna code that in actionPerformed?

if(joke.isClicked?) thats my problem thank you please help me dudes!

Comments

  • Dude, be specific with your questions. Refrace pls.
  • You can make a button handler, and in the handler you can use the function that you want to delete something.

    Example:
    public class Control extends JPanel
    {
    private JButton delete;
    
     public Control()
    {
    delete = new JButton("Delete Joke");
    delete.addActionListener(new HndDelete());
    
    add(delete)
    }
    
    public class HndDelete implements ActionListener
                {
                    @Override
                    public void actionPerformed(ActionEvent e)
                               **Perform your delete method here** Don't forget to refresh your GUI with like: repaint() or changeView()
                 }
    }
    }
    

    This above should do it! ^^
Sign In or Register to comment.