I want to change my JLabel every time a user selects a selection in JComboBox that gets its values ββfrom text files, you really need help ....
import javax.swing.*; import javax.swing.border.*; import java.util.*; import java.util.List; import java.io.IOException; import java.util.Scanner; import java.io.*; import java.awt.*; import java.awt.event.*; import java.net.*; import java.applet.*; public class MusicOnWeb extends JApplet { JPanel P = new JPanel(); JLabel Title = new JLabel(); JLabel Logo = new JLabel(); JLabel Category = new JLabel(); JLabel List = new JLabel(); JLabel Image = new JLabel(); JSeparator jSeparator1 = new JSeparator(); JSeparator jSeparator2 = new JSeparator(); JSeparator jSeparator3 = new JSeparator(); JSeparator jSeparator4 = new JSeparator(); JSeparator jSeparator5 = new JSeparator(); JButton Cc = new JButton(); JButton Pp = new JButton(); JButton Jz = new JButton(); JButton Wn = new JButton(); JButton Cart = new JButton(); JComboBox Combo1 = new JComboBox(); JComboBox Combo2 = new JComboBox(); JComboBox Combo3 = new JComboBox(); JComboBox Combo4 = new JComboBox(); Font f = new Font("Lucida Calligraphy", Font.BOLD,25); final java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM dd yyyy GGG hh:mm:ss aaa"); JLabel TimeLabel = new JLabel(); ActionListener al = new ActionListener() { public void actionPerformed(ActionEvent ae) { TimeLabel.setText(sdf.format(new java.util.Date())); } }; String[] CB1 = new String[5]; String[] CB2 = new String[5]; String[] CB3 = new String[5]; String[] CB4 = new String[5]; String Music [ ] = {" Seal.jpg"}; GridBagConstraints gbc; public void init() { P.setBackground(new Color(102, 102, 102)); P.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 0, 51), new java.awt.Color(0, 153, 255), new java.awt.Color(0, 204, 153), new java.awt.Color(0, 204, 102)), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 3))); P.setLayout(new GridBagLayout()); try { File F= new File("Classics.txt"); Scanner inFile = new Scanner(new FileReader(F)).useDelimiter("\\' '| \r"); int i=0; while (inFile.hasNextLine()){ CB1[i] = inFile.nextLine(); i++; }} catch (Exception e) { } try { File F= new File("Western.txt"); Scanner inFile = new Scanner(new FileReader(F)).useDelimiter("\\' '| \r"); int i=0; while (inFile.hasNextLine()){ CB2[i] = inFile.nextLine(); i++; }}catch (Exception e) { } try { File F= new File("Pop.txt"); Scanner inFile = new Scanner(new FileReader(F)).useDelimiter("\\' '| \r"); int i=0; while (inFile.hasNextLine()){ CB4[i] = inFile.nextLine(); i++; }}catch (Exception e) { } try { File F= new File("Jazz.txt"); Scanner inFile = new Scanner(new FileReader(F)).useDelimiter("\\' '| \r"); int i=0; while (inFile.hasNextLine()){ CB3[i] = inFile.nextLine(); i++; }}catch (Exception e) { } Title.setFont(new Font("Lucida Calligraphy", 1, 27)); Title.setForeground(new Color(102, 102, 255)); Title.setHorizontalAlignment(SwingConstants.CENTER); Title.setText("<HTML><center><b><u>MusicOnWeb</u></b><BR>An Online Music Store</HTML>"); Title.setBorder(javax.swing.BorderFactory.createLineBorder(new Color(0, 0, 0))); gbc = new GridBagConstraints(); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 10; gbc.ipadx = 440;
source share