I made this aplication on Eclipse for a school project. It's just suppose to run a video when a button is press. In the IDE everything works fine, althought an error occures but doesn't cause any trouble (Will leave it, thought, so if it causes something I want to now.)
Now, when I export the Jar file and try to run it, in the same computer, video doesn't play. What can I do?
JFrame vid = new JFrame();
vid.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
vid.setBounds(100, 100, 450, 300);
vid.setVisible(true);
Canvas c = new Canvas();
c.setBackground(Color.BLACK);
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(c);
vid.add(p);
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"C:/Program Files/VideoLAN/VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
MediaPlayerFactory mpf = new MediaPlayerFactory();
EmbeddedMediaPlayer emp = mpf.newEmbeddedMediaPlayer(new Win32FullScreenStrategy(vid));
emp.setVideoSurface(mpf.newVideoSurface(c));
emp.toggleFullScreen();
emp.setEnableMouseInputHandling(false);
emp.setEnableKeyInputHandling(false);
String file="/resources/sky.mp4";
emp.prepareMedia(file);
emp.play();
Here is the error code that appears:
[0000000017a2b420] core vout display error: Failed to set on top
Please, help me, as I need the project to work.
Okay, I got to work it around a bit.
As I can't use a URL instead of String, and String doesn't let me do a Class#getResource, I finally decide to run it from a public folder which should not change, in theory, from pc to pc.
So my code end up being:
String file = new File("C:/Users/Public/Videos/sky.mp4").getAbsolutePath();
emp.prepareMedia(file);
emp.play();
While not ideal to pass without guidance, as we will be installing the program, it does the job.
Related
so my problem is quite bizarre. So I am trying to write a java program in the eclipse ide. I have one JFrame and multiple JPanels added to it. You can navigate through the JPanels via buttons setting one panel to not be visible and another to be visible, you get the idea. However, after some time this started to occur: when I press a button the correct JPanel is being set to visible and I can see it, but it is completely empty. Sometimes its content is displayed correctly, but this is rather inconsistent.
As I said: sometimes this happens, sometimes it doesnt happen. I would start the program and close it 5 times and the 6th time it finally works. I don't think the code is necessary (as it is all correct because, after all, it does work sometimes), but if you want to see it feel free to ask. My eclipse workspace is on my C drive on an SSD and it is not too full. it has like 100 out of 250 gigs left. Thank you for your time and help in advance!
Edit:
So heres the code example.
Two of the JPanels Im trying to switch between:
The "main" panel
Var.menuPanel = new JPanel();
Var.jf1.add(Var.menuPanel);
Var.menuPanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.menuPanel.setLayout(null);
Var.menuPanel.setVisible(true);
Var.menuPanel.revalidate();
Var.menuPanel.repaint();
This loads all fine.
The button to switch to the other panel:
Var.editCourse = new JButton("Edit");
Var.menuPanel.add(Var.editCourse);
Var.editCourse.setBounds(550, 120, 200, 50);
Var.editCourse.setVisible(true);
Var.editCourse.addActionListener(handler);
Var.editCourse.setBackground(Color.YELLOW);
The other JPanel + UI elements
Var.editCoursePanel = new JPanel();
Var.jf1.add(Var.editCoursePanel);
Var.editCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.editCoursePanel.setLayout(null);
Var.editCoursePanel.setVisible(false);
Var.editCoursePanel.revalidate();
Var.editCoursePanel.repaint();
Var.editCourseToMenu = new JButton("Back");
Var.editCoursePanel.add(Var.editCourseToMenu);
Var.editCourseToMenu.setVisible(true);
Var.editCourseToMenu.setBounds(550, 400, 200, 50);
Var.editCourseToMenu.addActionListener(handler);
Var.editCourseSelection = new JComboBox<String>(JSONHandler.courses);
Var.editCoursePanel.add(Var.editCourseSelection);
Var.editCourseSelection.setBounds(550, 200, 200, 50);
Var.editCourseSelection.setVisible(true);
Methods.setArrowBounds(Var.editCourseSelection);
Var.editCourseSelection.setSelectedItem("Edit.");
Var.submitCourse = new JButton("Continue");
Var.editCoursePanel.add(Var.submitCourse);
Var.submitCourse.setBounds(550, 300, 200, 50);
Var.submitCourse.setVisible(true);
Var.submitCourse.addActionListener(handler);
The line in the AcionHandler:
else if(e.getSource() == Var.editCourse) {
MenuHandler.showEditCoursePanel();
}
The showEditCoursePanel methtod:
public static void showEditCoursePanel() {
Var.menuPanel.setVisible(false);
Var.editCoursePanel.setVisible(true);
}
Oh and also, sometimes when it doesnt load, there is the scrollbar of a JScrollPane on the side, which, as you can see, is never even mentioned.
Edit 2:
Okay, I found the source of the problem. When I add the raw JPanel to the JFrame and workt with that it all works fine, I cant scroll of course. But when I add the JScrollPane the newCoursePanel doesnt show up at all. Everything else is now working fluently, except for the panel with the scrollbar. Heres the code form the nwCoursePanel im talking about:
Var.newCoursePanel = new JPanel();
Var.newCoursePanel.setBounds(0, 0, Var.screenwidth, Var.screenheight);
Var.newCoursePanel.setLayout(null);
Var.newCoursePanel.revalidate();
Var.newCoursePanel.repaint();
Var.newCoursePane = new JScrollPane(Var.newCoursePanel);
Var.newCoursePane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
Var.newCoursePane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
Var.newCoursePane.setVisible(false);
Var.jf1.add(Var.newCoursePane);
I cant figure out how to get it working though. in to show the panel I just Var.menuPanel.setVisible(false) and Var.newCoursePane.setVisible(true).
jOptionPane dont show on top windows.
I've read that using
JFrame frmOpt = new JFrame();
frmOpt.setVisible(true);
frmOpt.setLocation(100, 100);
frmOpt.setAlwaysOnTop(true);
should be enough, but the problems is that I'm using Java 1.4 and 'setAlwaysOnTop' does not exists.
so....is there a way to solve this situation?
thanks in advance.
EDIT: Here is what I'm doing:
JFrame frmOpt = new JFrame();
frmOpt.setVisible(false);
response = JOptionPane.showOptionDialog(frmOpt,message,mens, 0,JOptionPane.OK_CANCEL_OPTION,null,options,null);
First I create a JFrame, then I create a new JOptionFrame setting the JFrame.
And it still shows at the back. Notice I do not use setAlwaysOnTop because of Java 1.4
I've searched quite a few threads here but none have helped.
I have a few JFrames and each JFrame should have its own individual cursor, symbolizing which version of the program the user is using.
These files are in /AndroidToolkit/resources. The files are all .cur files, so they're actually proper cursors and not just images.
I've tried a few methods of doing this, but I have succeeded. I've tried using ImageIO, Toolkit, and my last try was:
Cursor cCur = Toolkit.getDefaultToolkit().createCustomCursor(getClass().getResource("../resources/ImpressionCursor.cur").getFile()., null, null);
How can I do this in an easy way, which is easy for other people to understand, without me having to always comment it with 10k lines?
Thanks in advance,
Beats
This is what you need, try this code 100% works for me on Ubuntu 12.04 LTS, it should work for you too:
public static void main(String[] args) {
Toolkit toolKit = Toolkit.getDefaultToolkit();
Image pencil = toolKit.getImage("pencil.gif");
Cursor cursor = toolKit.createCustomCursor(pencil, new Point(0, 0), "Pencil");
JFrame frame = new JFrame("Cursor Test");
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setCursor(cursor);
frame.setVisible(true);
}
this is the link for the gif file click here,
I hope that helps, Salam
Well I was wondering if I could make an icon image for a JFrame. I do know its posible, because, let me say, I am NOT digging the java logo.
Well if I just hava to use a Frame object I will.
Can someone tell me, I know its possible!
Use an ImageIcon.
ImageIcon icon = new ImageIcon( pathToIcon );
yourFrame.setIconImage(icon.getImage());
Good Luck!
First, you have to have an image file on your computer. It can be named anything. For this example, we will call this one "pic.jpg".
Next, you need to include it in the files that your application is using. For example, if you're using NetBeans, you simply click on "Files" in the left hand side of the IDE (not File as in the menu, mind you). Drag the picture's file over to the folder that houses the main package. This will include it for available use in the code.
Inside the method where you define the JFrame, you can create an image like this:
Image frameImage = new ImageIcon("pic.jpg").getImage();
You can now set it as the IconImage for the frame like this:
JFrame frame = new JFrame("Title");
frame.setIconImage(frameImage);
Hope that's helpful.
Note: the reason that the Image object has to be created like this is because Image is abstract and cannot be instantiated by saying new Image();
Props to you, btw, kid. I wish I would have started learning programming when I was your age. Keep at it!
You can do the following.
public Test {
public static void main(String[] args) {
JFrame frame = new JFrame("My Frame");
frame.setIconImage(new ImageIcon(Test.class.getResource("image.png"));
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
frame.setSize(100, 100);
//other stuffs....
}
}
So in this application I'm making, the user clicks on a button, and that button launches a program. This button will have the title of the application and the icon. I just need to know how to get the icon, kind of like this: Windows http://goo.gl/5WjdT
So what I want to know is this:
Is there any REAL way to do this in Java
If so, how would you do it?
Thanks in advance!
Do you have to get the icon associated to the exe file of the application ? If so it is possible in java, take a look at this tutorial, that explain several ways of extracting app icon from an executable binary file from a Java application.
Take a look at this code :
String s = "c:/windows/regedit.exe";
File file = new File(s);
// Get metadata and create an icon
sun.awt.shell.ShellFolder sf =
sun.awt.shell.ShellFolder.getShellFolder(file);
Icon icon = new ImageIcon(sf.getIcon(true));
You can simply use FileSystemView for that purpose:
public static void main(String[] args) {
Icon icon = FileSystemView.getFileSystemView()
.getSystemIcon(new File("C:\\Windows\\regedit.exe"));
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JLabel(icon));
frame.pack();
frame.setVisible(true);
}