Heloic Posted October 27, 2012 Share Posted October 27, 2012 This is the code to download a file URL website = new URL("http://www.website.com/information.asp"); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); FileOutputStream fos = new FileOutputStream("information.html"); fos.getChannel().transferFrom(rbc, 0, 1 << 24); and this my java page i want it to work in. package layout; /* * TabDemo.java */ import java.awt.*; import javax.swing.*; public class TabDemo { final static String HOMEBUTTONPANEL = "Home"; final static String MAINBUTTONPANEL = "Main Plugins"; final static String ECONOMYBUTTONPANEL = "Economy Plugins"; final static String FUNBUTTONPANEL = "Fun Plugins"; final static String PERMBUTTONPANEL = "Permissions Plugins"; final static String WORLDMODBUTTONPANEL = "World Modifiers"; final static int extraWindowWidth = 600; final static int extraWindowHeight = 600; public void addComponentToPane(Container pane) { JTabbedPane tabbedPane = new JTabbedPane(); //Create the "cards". JPanel card1 = new JPanel() { //Make the panel wider than it really needs, so //the window's wide enough for the tabs to stay //in one row. public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width += extraWindowWidth; size.height += extraWindowHeight; return size; } }; JPanel card2 = new JPanel(); card2.add(new JButton("Chest Shop")); card2.add(new JButton("Essentials")); card2.add(new JButton("Factions")); card2.add(new JButton("GroupManager")); card2.add(new JButton("Iconomy")); card2.add(new JButton("Kingdoms")); card2.add(new JButton("PermissionsEx")); //Breakline here card2.add(new JButton("Towny")); card2.add(new JButton("World Border")); card2.add(new JButton("World Edit")); card2.add(new JButton("World Guard")); tabbedPane.addTab(HOMEBUTTONPANEL, card1); tabbedPane.addTab(MAINBUTTONPANEL, card2); pane.add(tabbedPane, BorderLayout.CENTER); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event dispatch thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("Minecraft Server Plugin Downloader"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. TabDemo demo = new TabDemo(); demo.addComponentToPane(frame.getContentPane()); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { /* Use an appropriate Look and Feel */ try { //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); } catch (UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } catch (IllegalAccessException ex) { ex.printStackTrace(); } catch (InstantiationException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } /* Turn off metal's use of bold fonts */ UIManager.put("swing.boldMetal", Boolean.FALSE); //Schedule a job for the event dispatch thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } } How can i make it work so, that when i click card2.add(new JButton("Chest Shop")); this button it downloads a certain file? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.