kelly bones

Greenhorn
+ Follow
since Jan 18, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kelly bones

Hi again y'all

Thanks for the pointers.

Jim - using a while loop and forcing a read from the link you posted me is tricky.

I've got round the problem temporarily by testing for a null array - i.e. a fail condition, and forcing my file read method to re-run until it works, and I now get a display even if it has to loop a couple of times. but I'm not sure why the readFully() doesn't always correctly fill the array?

I'd be much happier if I could understand this?



Can anyone spot logic or code problems for me please? kelly
17 years ago
thank you Jim - there's more to IO than meets the eye

kelly
17 years ago
Many thanks Joe - off to read the API - again!

kelly
17 years ago
Hi Guys

I'm trying to read a stream into a byte array using FileInputStream reads(byte[] ) etc


This works about 50% of the time, but when it fails my test is a System.out.println testing if the data1D[] is not "null" in an inner class used to display, and this seems to confirm the array is empty.

Any advice gratefully recd

love

kelly
17 years ago
many thanks for you help - the [trackNo--] was my typo! typical!

love

kelly
19 years ago
hi yes I don't want a given answer it's jsut I may be missin a simple option her and getting a bit confised with types.

I have tried to navigate about my JList using SelectedIndex / SelectedValue (get & set) but run into a few problems with the types clashing (index needing int and value being the file path & name object).

my code runs but htis latest development is proving a bit tricky:



when I try to call the next track



doesn't work

This is very 'bitty' but it is a long code listing to post it all

any advice where to look next will be much appreciated

love

kelly
19 years ago
I have populated a JList from a DefaultListModel. When an item in JList is selected it plays an MP3 file which can fire an event to signal the MP3 track has ended.

Is there an index I can increment in JList or do I have to go back to the DefaultListModel and then find the appropriate JList entry to play the next track automatically please?

kelly
19 years ago
many thanks for your help - and a good nights sleep helped resolve it.

sorry - hate to admit it but I had a path problem with the image files

love

kelly
19 years ago
hi Jeff
have tried all sorts of re-size and re-organising layout

code snippet:
private void initGui()
{
Container theContainer = getContentPane(); // add swing components here
mainPanel = new JPanel()
{ImageIcon image = new ImageIcon("Images\\Clifton_Bridge.jpg");
{setOpaque(false);} public void paintComponent (Graphics g)
{ g.drawImage(image.getImage(), 0, 0, this); super.paintComponent(g);}
};
mainPanel.setLayout(new BorderLayout());

listModel = new DefaultListModel();
list = new JList(listModel);
list.setOpaque(false);
listModel.addElement("<<your playlist files>>");
JScrollPane scrollPane = new JScrollPane(list);
list.setCellRenderer(new MyCellRenderer());
scrollPane.setOpaque(false);
scrollPane.setBorder(null);
scrollPane.getViewport().setOpaque(false);

list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new ListSelectionListener()
{ public void valueChanged(ListSelectionEvent e)
{if (e.getValueIsAdjusting()) return;
System.out.println(list.getSelectedValue());
if (list.getSelectedIndex() > 0)
player.start(list.getSelectedValue().toString());
}
});

listPanel = new JPanel();//holds playlist
listPanel.setLayout(new BorderLayout());
listPanel.setPreferredSize(new Dimension(50,50));
listPanel.setOpaque(false);
listPanel.add(scrollPane, BorderLayout.CENTER);

controlPanel = new JPanel();//holds icon panel [control buttons]
controlPanel.setLayout(new BorderLayout());
controlPanel.setOpaque(false);
controlPanel.setPreferredSize(new Dimension(500,100));

iconPanel = new JPanel();//holds control buttons
iconPanel.setPreferredSize(new Dimension(500,80));
iconPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
iconPanel.setOpaque(false);

gridPanel = new JPanel();// sets output text
gridPanel.setLayout(new GridLayout(4,2));
gridPanel.setPreferredSize(new Dimension(580, 120));
gridPanel.setOpaque(false);

stopButton = createBaseButton("Stop", 20, 20); // stopButton
stopButton.setIcon(new ImageIcon("Images\\Stop_B&W.GIF"));
stopButton.setRolloverIcon(new ImageIcon("Images\\Stop_Green.GIF"));
stopButton.setPressedIcon(new ImageIcon("Images\\Stop_Red.GIF"));
iconPanel.add(stopButton);
stopButton.addActionListener(this);

prevButton = createBaseButton("Prev", 20, 20); // prevButton
prevButton.setIcon(new ImageIcon("Images\\Prev_B&W.GIF"));
prevButton.setRolloverIcon(new ImageIcon("Images\\Prev_Green.GIF"));
prevButton.setPressedIcon(new ImageIcon("Images\\Prev_Red.GIF"));
iconPanel.add(prevButton);
prevButton.addActionListener(this);

pauseButton = createBaseButton("Pause", 20, 20); // pauseButton
pauseButton.setIcon(new ImageIcon("Images\\Pause_B&W.GIF"));
pauseButton.setRolloverIcon(new ImageIcon("Images\\Pause_Green.GIF"));
pauseButton.setPressedIcon(new ImageIcon("Images\\Pause_Red.GIF"));
iconPanel.add(pauseButton);
pauseButton.addActionListener(this);

playButton = createBaseButton("Play", 20, 20);// playButton
playButton.setIcon(new ImageIcon("Images\\Play_B&W.GIF"));
playButton.setRolloverIcon(new ImageIcon("Images\\Play_Green.GIF"));
playButton.setPressedIcon(new ImageIcon("Images\\Play_Red.GIF"));
iconPanel.add(playButton);
playButton.addActionListener(this);

controlPanel.add(iconPanel, BorderLayout.SOUTH);

artist = new JLabel("Artist");
album = new JLabel("Album");
title = new JLabel("Track");
time = new JLabel("Time");

top = new JPanel();//holds title right justified
top.setOpaque(false);
top.setLayout(new FlowLayout(FlowLayout.TRAILING));
top.setPreferredSize(new Dimension(500,110));
JLabel name = new JLabel("Java MP3 Player");
top.add(name);

gridPanel.add(artist);
gridPanel.add(album);
gridPanel.add(title);
gridPanel.add(time);

lpan = new JPanel();//padding to left side of GUI
lpan.setOpaque(false);
lpan.setPreferredSize(new Dimension(50,200));

rpan = new JPanel();//padding to right side of GUI
rpan.setOpaque(false);
rpan.setPreferredSize(new Dimension(50,200));

textPanel = new JPanel();// holds list and labels output
textPanel.setPreferredSize(new Dimension(480, 200));
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
textPanel.setOpaque(false);
textPanel.add(gridPanel);
textPanel.add(listPanel);

mainPanel.setPreferredSize(new Dimension(580, 466));
mainPanel.add(controlPanel, BorderLayout.SOUTH);
// mainPanel.add(iconPanel, BorderLayout.SOUTH);
mainPanel.add(top, BorderLayout.NORTH);
mainPanel.add(lpan, BorderLayout.WEST);
mainPanel.add(rpan, BorderLayout.EAST);
mainPanel.add(textPanel, BorderLayout.CENTER);

theContainer.add(mainPanel);
setLocation(50,100);
}// end of initGUI()

the new button added is prevButton which follows all other JButton styles with roll over images etc. When I look closely at the running code there is a blank 'grey' 20 x 20 pixel square between the stop and pause JHButtons which is the place I expected to find prevButton. I tried it here after it failed to appear to the left of stopButton?
still mystified?

it is clearly my college assignment. I'm reasonably happy with my code so far but this is really stumping me? any ideas for solving would be very much appreciated - love

Kelly
19 years ago
hello - new to this bbs - hope this is right place to post query - it is from a newby but may be swing?

a new button(4th) does not appear in my gui, yet all other buttons(3) appear - any advice on where to look for error please?

code is copied form other buttons which work and display as expected?

mystified

love

kelly
19 years ago