Download program do not work when gui is implemented

Download program do not work when gui is implemented. It works fine wi

Page 1 of 1

9 Replies - 2005 Views - Last Post: 03 March 2009 - 04:15 AM Rate Topic: -----

#1 myxbaah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-February 09

Download program do not work when gui is implemented

Post icon  Posted 28 February 2009 - 04:33 AM

Hello
I am very new to java. In fact I started it last week.

I want to implement a code in to a GUI with a 2 text fields
- One for URL
- One for Number of Chapters
However when I do it it does not work when i did it

Here is the code. Have a look and tell me what is wrong with it.

/*
 * OneManga.java
 *
 */

package OneManga;


import java.io.*;
import java.net.*;
import java.util.StringTokenizer;


public class OneManga extends javax.swing.JFrame {

	/** Creates new form OneManga */
	public OneManga() {
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jTabbedPane1 = new javax.swing.JTabbedPane();
		jPanel1 = new javax.swing.JPanel();
		jLabel1 = new javax.swing.JLabel();
		jTextField1 = new javax.swing.JTextField();
		jLabel2 = new javax.swing.JLabel();
		jTextField2 = new javax.swing.JTextField();
		jProgressBar1 = new javax.swing.JProgressBar();
		jButton1 = new javax.swing.JButton();
		jPanel2 = new javax.swing.JPanel();
		jButton2 = new javax.swing.JButton();
		jButton3 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jLabel1.setText("Url");

		jTextField1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jTextField1ActionPerformed(evt);
			}
		});

		jLabel2.setText("Number of Chapters");

		jButton1.setText("Clear");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
		jPanel1.setLayout(jPanel1Layout);
		jPanel1Layout.setHorizontalGroup(
			jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(jPanel1Layout.createSequentialGroup()
				.addContainerGap()
				.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
					.addGroup(jPanel1Layout.createSequentialGroup()
						.addComponent(jLabel1)
						.addGap(18, 18, 18)
						.addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE))
					.addGroup(jPanel1Layout.createSequentialGroup()
						.addComponent(jLabel2)
						.addGap(18, 18, 18)
						.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
					.addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
				.addContainerGap())
		);
		jPanel1Layout.setVerticalGroup(
			jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(jPanel1Layout.createSequentialGroup()
				.addContainerGap()
				.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(jLabel1)
					.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
				.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(jLabel2)
					.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
				.addGap(27, 27, 27)
				.addComponent(jButton1)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
				.addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addContainerGap(21, Short.MAX_VALUE))
		);

		jTabbedPane1.addTab("Download 1", jPanel1);

		javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
		jPanel2.setLayout(jPanel2Layout);
		jPanel2Layout.setHorizontalGroup(
			jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 375, Short.MAX_VALUE)
		);
		jPanel2Layout.setVerticalGroup(
			jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGap(0, 166, Short.MAX_VALUE)
		);

		jTabbedPane1.addTab("Credits", jPanel2);

		jButton2.setText("Download");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		jButton3.setText("Exit");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
					.addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING))
				.addContainerGap())
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
				.addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
				.addGap(28, 28, 28)
				.addComponent(jButton2)
				.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
				.addComponent(jButton3)
				.addContainerGap())
		);

		pack();
	}// </editor-fold>//GEN-END:initComponents
	static int aval;

	private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
		// TODO add your handling code here:
	}//GEN-LAST:event_jTextField1ActionPerformed

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
		System.exit(0);
	}//GEN-LAST:event_jButton3ActionPerformed

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
		jTextField1.setText("");
		jTextField2.setText("");
	}//GEN-LAST:event_jButton1ActionPerformed

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
		jButton2.addActionListener(new download());
	}//GEN-LAST:event_jButton2ActionPerformed

	/**
	* @param args the command line arguments
	*/
		 public void fdownload(String address, String localFileName)
	{
		OutputStream out;
		InputStream in;
		out = null;
		URLConnection conn = null;
		in = null;
		try
		{
			URL url = new URL(jTextField1.getText());
			out = new BufferedOutputStream(new FileOutputStream(localFileName));
			URLConnection conn = url.openConnection();
			in = conn.getInputStream();
			byte buffer[] = new byte[1024];
			int numRead;
			long numWritten;
			for(numWritten = 0L; (numRead = in.read(buffer)) != -1; numWritten += numRead)
				out.write(buffer, 0, numRead);

			BufferedInputStream buff= new BufferedInputStream(conn.getInputStream());
			//  size1=Integer.valueOf(buff.toString());
			aval=  buff.available();

			System.out.println((new StringBuilder(String.valueOf(localFileName))).append("\t").append(numWritten).toString());
			break MISSING_BLOCK_LABEL_183;
		}
		catch(Exception exception)
		{
			exception.printStackTrace();
		}
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception) { }
		break MISSING_BLOCK_LABEL_206;
		Exception exception1;
		exception1;
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception1) { }
		throw exception1;
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception2) { }
	}

	public void downloadMh(String address)
	{
		int lastSlashIndex = address.lastIndexOf('/');
		int last = currentURL.lastIndexOf('/');
		int x;
		for(x = 1; currentURL.charAt(last - x) != '/'; x++);
		for(int y = x + 1; currentURL.charAt(last - y) != '/'; y++);
		(new File((new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - x) + 1, last)).toString())).mkdir();
		String ot = (new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - x) + 1, last)).append(address.substring(lastSlashIndex)).toString();
		System.out.println(ot);
		if(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)
			fdownload(address, ot);
		else
			System.err.println((new StringBuilder("Could not figure out local file name for ")).append(address).toString());
	}

	public static void download(String address)
	{
		int lastSlashIndex = address.lastIndexOf('/');
		int last = currentURL.lastIndexOf('/');
		int x;
		for(x = 1; currentURL.charAt(last - x) != '/'; x++);
		int y;
		for(y = x + 1; currentURL.charAt(last - y) != '/'; y++);
		(new File((new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).toString())).mkdir();
		String ot = (new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).append(address.substring(lastSlashIndex)).toString();
		System.out.println(ot);
		if(Integer.parseInt(currentURL.substring((last - y) + 1, last - x)) != lastCHAPTER)
		{
			c++;
			if(c > chapters)
				System.exit(-1);
		}
		lastCHAPTER = Integer.parseInt(currentURL.substring((last - y) + 1, last - x));
		if(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)
			fdownload(address, ot);
		else
			System.err.println((new StringBuilder("Could not figure out local file name for ")).append(address).toString());
	}

	public static boolean testStringmh(String test)
	{
		StringTokenizer temp = new StringTokenizer(test, "[");
		if(temp.hasMoreElements() && temp.nextToken().equals("scans"))
		{
			temp = new StringTokenizer(test, "\"");
			temp.nextToken();
			downloadMh(temp.nextToken());
			return false;
		}
		for(temp = new StringTokenizer(test); temp.hasMoreElements();)
			if(temp.nextToken().equals("type='text/javascript'>nextchapter"))
			{
				System.out.println(temp.nextToken());
				String tst;
				for(tst = ""; temp.hasMoreElements(); tst = (new StringBuilder(String.valueOf(tst))).append(temp.nextToken()).append("%20").toString());
				if(tst.equals("'';</script>%20"))
					System.exit(-1);
				temp = new StringTokenizer(tst, "'");
				nextURL = (new StringBuilder(String.valueOf(defaultURL))).append("/manga/").append(temp.nextToken()).append("/pg1").toString();
				System.out.println(nextURL);
				c++;
				return true;
			}

		return false;
	}

	public static boolean testStringom(String test)
	{
		String out = "";
		for(StringTokenizer temp = new StringTokenizer(test); temp.hasMoreTokens();)
		{
			String la = temp.nextToken();
			String nexturl = defaultURL;
			if(la.equals("The End.</h1>") || la.equals("available"))
				System.exit(1);
			if(la.equals("window.location") && !chosen)
			{
				temp.nextToken();
				la = temp.nextToken();
				for(int x = 1; la.charAt(x + 1) != ';'; x++)
					nexturl = (new StringBuilder(String.valueOf(nexturl))).append(la.charAt(x)).toString();

				System.out.println(nexturl);
				nextURL = nexturl;
				chosen = true;
			}
			if(la.charAt(0) == 'c' && la.charAt(1) == 'l' && la.charAt(2) == 'a' && la.charAt(3) == 's' && la.charAt(4) == 's' && la.charAt(5) == '=' && la.charAt(6) == '"' && la.charAt(7) == 'm')
			{
				la = temp.nextToken();
				int x;
				for(x = 1; la.charAt(x) != 'h'; x++);
				for(; la.charAt(x) != '"'; x++)
					out = (new StringBuilder(String.valueOf(out))).append(la.charAt(x)).toString();

				System.out.println(out);
				download(out);
				return true;
			}
		}

		return false;
	}

	public static void main(String args[])
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new OneManga().setVisible(true);
			}
		});
		StringTokenizer la = new StringTokenizer(args[0], "/");
		la.nextToken();
		String tmp = la.nextToken();
		if(args.length > 1)
			chapters = Integer.parseInt(args[1]);
		if(tmp.equals("www.onemanga.com"))
		{
			defaultURL = "http://www.onemanga.com";
			oneManga(args[0]);
		} else
		if(tmp.equals("www.mangahut.com"))
		{
			defaultURL = "http://www.mangahut.com";
			mangaHut(args[0]);
		}
	}

	public static void mangaHut(String s)
	{
		BufferedReader in = null;
		StringTokenizer la = new StringTokenizer(s, "/");
		for(int i = 0; i < 3; i++)
			la.nextToken();

		folder = la.nextToken();
		(new File(folder)).mkdir();
		currentURL = s;
		try
		{
			URL url = new URL(s);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			for(String output = null; (output = in.readLine()) != null;)
				if(testStringmh(output))
				{
					if(c >= chapters)
						System.exit(-1);
					url = new URL(nextURL);
					currentURL = nextURL;
					in = new BufferedReader(new InputStreamReader(url.openStream()));
					output = null;
					chosen = false;
				}

		}
		catch(MalformedURLException ex)
		{
			System.err.println(ex);
		}
		catch(FileNotFoundException ex)
		{
			System.err.println((new StringBuilder("Failed to open stream to URL: ")).append(ex).toString());
		}
		catch(IOException ex)
		{
			System.err.println((new StringBuilder("Error reading URL content: ")).append(ex).toString());
		}
		if(in != null)
			try
			{
				in.close();
			}
			catch(IOException ioexception) { }
	}

	public static void oneManga(String s)
	{
		BufferedReader in = null;
		int x = 1;
		try
		{
			currentURL = s;
			int last;
			for(last = currentURL.lastIndexOf('/'); currentURL.charAt(last - x) != '/'; x++);
			int y;
			for(y = x + 1; currentURL.charAt(last - y) != '/'; y++);
			x = y;
			for(y++; currentURL.charAt(last - y) != '/'; y++);
			URL url = new URL(s);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			String output = null;
			folder = currentURL.substring((last - y) + 1, last - x);
			System.out.println(folder);
			(new File(folder)).mkdir();
			while((output = in.readLine()) != null)
				if(testStringom(output))
				{
					url = new URL(nextURL);
					currentURL = nextURL;
					in = new BufferedReader(new InputStreamReader(url.openStream()));
					output = null;
					chosen = false;
				}
		}
		catch(MalformedURLException ex)
		{
			System.err.println(ex);
		}
		catch(FileNotFoundException ex)
		{
			System.err.println((new StringBuilder("Failed to open stream to URL: ")).append(ex).toString());
		}
		catch(IOException ex)
		{
			System.err.println((new StringBuilder("Error reading URL content: ")).append(ex).toString());
		}
		if(in != null)
			try
			{
				in.close();
			}
			catch(IOException ioexception) { }
	}

	static int c = 0;
	static int lastCHAPTER;
	static String defaultURL = "http://www.onemanga.com";
	static boolean chosen = false;
	static String nextURL = "";
	static String currentURL = "";
	static String folder;
	static int chapters = 0x7fffffff;



	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton jButton1;
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JPanel jPanel1;
	private javax.swing.JPanel jPanel2;
	private javax.swing.JProgressBar jProgressBar1;
	private javax.swing.JTabbedPane jTabbedPane1;
	private javax.swing.JTextField jTextField1;
	private javax.swing.JTextField jTextField2;
	// End of variables declaration//GEN-END:variables

}



BTW i use Net Beans IDE to program java.

I need help soon

This post has been edited by myxbaah: 28 February 2009 - 09:10 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Download program do not work when gui is implemented

#2 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Download program do not work when gui is implemented

Posted 28 February 2009 - 11:54 AM

If you just started Java you should not just download a gui program and tell us to finjd the problems you should start by writing a console application from scratch and if you have errors see if you find them, if not then post the errors here and what you have tried so we can assist you.

Learning Java is like building a pyramid. You cant start toward the top (GUIS) and expect the other experts to tell you why it keeps tumbling down.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Download program do not work when gui is implemented

Posted 28 February 2009 - 06:49 PM

:^: BigAnt
Was This Post Helpful? 0
  • +
  • -

#4 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Download program do not work when gui is implemented

Posted 28 February 2009 - 07:03 PM

View Postpbl, on 28 Feb, 2009 - 05:49 PM, said:

:^: BigAnt


:ph34r:

Also @ topic creator, do not make a GUI using an IDE and expect us to shift through the generated code and make sense of it.
Especially net beans as the gui code tends to use layouts like:
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 355, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 324, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())


Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8325
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Download program do not work when gui is implemented

Posted 28 February 2009 - 09:54 PM

BigAnt agree 100% with you
have a look there:

http://www.dreaminco...h...pid=557683&
Was This Post Helpful? 0
  • +
  • -

#6 myxbaah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-February 09

Re: Download program do not work when gui is implemented

Posted 01 March 2009 - 08:18 AM

Well here is the source code for Console program

It works fine when used

java OneManga "URL" "No.of chapters"

import java.io.*;
import java.net.*;
import java.util.StringTokenizer;

public class OneManga
{

	public OneManga()
	{
	}

	public static void fdownload(String address, String localFileName)
	{
		OutputStream out;
		InputStream in;
		out = null;
		URLConnection conn = null;
		in = null;
		try
		{
			URL url = new URL(address);
			out = new BufferedOutputStream(new FileOutputStream(localFileName));
			URLConnection conn = url.openConnection();
			in = conn.getInputStream();
			byte buffer[] = new byte[1024];
			int numRead;
			long numWritten;
			for(numWritten = 0L; (numRead = in.read(buffer)) != -1; numWritten += numRead)
				out.write(buffer, 0, numRead);

			System.out.println((new StringBuilder(String.valueOf(localFileName))).append("\t").append(numWritten).toString());
			break MISSING_BLOCK_LABEL_183;
		}
		catch(Exception exception)
		{
			exception.printStackTrace();
		}
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception) { }
		break MISSING_BLOCK_LABEL_206;
		Exception exception1;
		exception1;
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception1) { }
		throw exception1;
		try
		{
			if(in != null)
				in.close();
			if(out != null)
				out.close();
		}
		catch(IOException ioexception2) { }
	}

	public static void downloadMh(String address)
	{
		int lastSlashIndex = address.lastIndexOf('/');
		int last = currentURL.lastIndexOf('/');
		int x;
		for(x = 1; currentURL.charAt(last - x) != '/'; x++);
		for(int y = x + 1; currentURL.charAt(last - y) != '/'; y++);
		(new File((new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - x) + 1, last)).toString())).mkdir();
		String ot = (new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - x) + 1, last)).append(address.substring(lastSlashIndex)).toString();
		System.out.println(ot);
		if(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)
			fdownload(address, ot);
		else
			System.err.println((new StringBuilder("Could not figure out local file name for ")).append(address).toString());
	}

	public static void download(String address)
	{
		int lastSlashIndex = address.lastIndexOf('/');
		int last = currentURL.lastIndexOf('/');
		int x;
		for(x = 1; currentURL.charAt(last - x) != '/'; x++);
		int y;
		for(y = x + 1; currentURL.charAt(last - y) != '/'; y++);
		(new File((new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).toString())).mkdir();
		String ot = (new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).append(address.substring(lastSlashIndex)).toString();
		System.out.println(ot);
		if(Integer.parseInt(currentURL.substring((last - y) + 1, last - x)) != lastCHAPTER)
		{
			c++;
			if(c > chapters)
				System.exit(-1);
		}
		lastCHAPTER = Integer.parseInt(currentURL.substring((last - y) + 1, last - x));
		if(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)
			fdownload(address, ot);
		else
			System.err.println((new StringBuilder("Could not figure out local file name for ")).append(address).toString());
	}

	public static boolean testStringmh(String test)
	{
		StringTokenizer temp = new StringTokenizer(test, "[");
		if(temp.hasMoreElements() && temp.nextToken().equals("scans"))
		{
			temp = new StringTokenizer(test, "\"");
			temp.nextToken();
			downloadMh(temp.nextToken());
			return false;
		}
		for(temp = new StringTokenizer(test); temp.hasMoreElements();)
			if(temp.nextToken().equals("type='text/javascript'>nextchapter"))
			{
				System.out.println(temp.nextToken());
				String tst;
				for(tst = ""; temp.hasMoreElements(); tst = (new StringBuilder(String.valueOf(tst))).append(temp.nextToken()).append("%20").toString());
				if(tst.equals("'';</script>%20"))
					System.exit(-1);
				temp = new StringTokenizer(tst, "'");
				nextURL = (new StringBuilder(String.valueOf(defaultURL))).append("/manga/").append(temp.nextToken()).append("/pg1").toString();
				System.out.println(nextURL);
				c++;
				return true;
			}

		return false;
	}

	public static boolean testStringom(String test)
	{
		String out = "";
		for(StringTokenizer temp = new StringTokenizer(test); temp.hasMoreTokens();)
		{
			String la = temp.nextToken();
			String nexturl = defaultURL;
			if(la.equals("The End.</h1>") || la.equals("available"))
				System.exit(1);
			if(la.equals("window.location") && !chosen)
			{
				temp.nextToken();
				la = temp.nextToken();
				for(int x = 1; la.charAt(x + 1) != ';'; x++)
					nexturl = (new StringBuilder(String.valueOf(nexturl))).append(la.charAt(x)).toString();

				System.out.println(nexturl);
				nextURL = nexturl;
				chosen = true;
			}
			if(la.charAt(0) == 'c' && la.charAt(1) == 'l' && la.charAt(2) == 'a' && la.charAt(3) == 's' && la.charAt(4) == 's' && la.charAt(5) == '=' && la.charAt(6) == '"' && la.charAt(7) == 'm')
			{
				la = temp.nextToken();
				int x;
				for(x = 1; la.charAt(x) != 'h'; x++);
				for(; la.charAt(x) != '"'; x++)
					out = (new StringBuilder(String.valueOf(out))).append(la.charAt(x)).toString();

				System.out.println(out);
				download(out);
				return true;
			}
		}

		return false;
	}

	public static void main(String args[])
	{
		StringTokenizer la = new StringTokenizer(args[0], "/");
		la.nextToken();
		String tmp = la.nextToken();
		if(args.length > 1)
			chapters = Integer.parseInt(args[1]);
		if(tmp.equals("www.onemanga.com"))
		{
			defaultURL = "http://www.onemanga.com";
			oneManga(args[0]);
		} else
		if(tmp.equals("www.mangahut.com"))
		{
			defaultURL = "http://www.mangahut.com";
			mangaHut(args[0]);
		}
	}

	public static void mangaHut(String s)
	{
		BufferedReader in = null;
		StringTokenizer la = new StringTokenizer(s, "/");
		for(int i = 0; i < 3; i++)
			la.nextToken();

		folder = la.nextToken();
		(new File(folder)).mkdir();
		currentURL = s;
		try
		{
			URL url = new URL(s);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			for(String output = null; (output = in.readLine()) != null;)
				if(testStringmh(output))
				{
					if(c >= chapters)
						System.exit(-1);
					url = new URL(nextURL);
					currentURL = nextURL;
					in = new BufferedReader(new InputStreamReader(url.openStream()));
					output = null;
					chosen = false;
				}

		}
		catch(MalformedURLException ex)
		{
			System.err.println(ex);
		}
		catch(FileNotFoundException ex)
		{
			System.err.println((new StringBuilder("Failed to open stream to URL: ")).append(ex).toString());
		}
		catch(IOException ex)
		{
			System.err.println((new StringBuilder("Error reading URL content: ")).append(ex).toString());
		}
		if(in != null)
			try
			{
				in.close();
			}
			catch(IOException ioexception) { }
	}

	public static void oneManga(String s)
	{
		BufferedReader in = null;
		int x = 1;
		try
		{
			currentURL = s;
			int last;
			for(last = currentURL.lastIndexOf('/'); currentURL.charAt(last - x) != '/'; x++);
			int y;
			for(y = x + 1; currentURL.charAt(last - y) != '/'; y++);
			x = y;
			for(y++; currentURL.charAt(last - y) != '/'; y++);
			URL url = new URL(s);
			in = new BufferedReader(new InputStreamReader(url.openStream()));
			String output = null;
			folder = currentURL.substring((last - y) + 1, last - x);
			System.out.println(folder);
			(new File(folder)).mkdir();
			while((output = in.readLine()) != null) 
				if(testStringom(output))
				{
					url = new URL(nextURL);
					currentURL = nextURL;
					in = new BufferedReader(new InputStreamReader(url.openStream()));
					output = null;
					chosen = false;
				}
		}
		catch(MalformedURLException ex)
		{
			System.err.println(ex);
		}
		catch(FileNotFoundException ex)
		{
			System.err.println((new StringBuilder("Failed to open stream to URL: ")).append(ex).toString());
		}
		catch(IOException ex)
		{
			System.err.println((new StringBuilder("Error reading URL content: ")).append(ex).toString());
		}
		if(in != null)
			try
			{
				in.close();
			}
			catch(IOException ioexception) { }
	}

	static int c = 0;
	static int lastCHAPTER;
	static String defaultURL = "http://www.onemanga.com";
	static boolean chosen = false;
	static String nextURL = "";
	static String currentURL = "";
	static String folder;
	static int chapters = 0x7fffffff;

}


Was This Post Helpful? 0
  • +
  • -

#7 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Download program do not work when gui is implemented

Posted 01 March 2009 - 10:28 AM

So if the console application works fine, what problems are you having when making the GUI. If the problem is in the logic of how to do the calculations, etc post what the problem is.

If the problem is a GUI problem, then it is a netbeans problem, and don't expect anyone to try and shift through all the netbeans code and find the problem.
Was This Post Helpful? 0
  • +
  • -

#8 myxbaah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-February 09

Re: Download program do not work when gui is implemented

Posted 01 March 2009 - 10:42 AM

The problem I think is that the action listener implemented to the Download button is not downloading the files. Furthermore, I don't know how to get the number entered in the chapter textfield. Clear button and Exit button works. Plus how can I make the Progress bar work.
At the moment here is Download buttons code

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
		jButton2.addActionListener(new download());
	}


This post has been edited by myxbaah: 01 March 2009 - 10:44 AM

Was This Post Helpful? 0
  • +
  • -

#9 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Download program do not work when gui is implemented

Posted 01 March 2009 - 12:10 PM

Is download a class you have written which implements the ActionListener?
Second, why do you add another ActionListener of type download every time the button is clicked?
You get the text from a textfield by calling the appropriate method, I believe its getText(), check the API for these types of methods.
Finally I have no clue how NetBeans does JProgress bars. You will have to decide how you want the JProgressBar to update, based on what.
Was This Post Helpful? 0
  • +
  • -

#10 myxbaah  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 28-February 09

Re: Download program do not work when gui is implemented

Posted 03 March 2009 - 04:15 AM

I want the progress bar to upload based on the amount being downloaded.

download is the class
public static void download(String address)
	{
		int lastSlashIndex = address.lastIndexOf('/');
		int last = currentURL.lastIndexOf('/');
		int x;
		for(x = 1; currentURL.charAt(last - x) != '/'; x++);
		int y;
		for(y = x + 1; currentURL.charAt(last - y) != '/'; y++);
		(new File((new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).toString())).mkdir();
		String ot = (new StringBuilder(String.valueOf(folder))).append('/').append(currentURL.substring((last - y) + 1, last - x)).append(address.substring(lastSlashIndex)).toString();
		System.out.println(ot);
		if(Integer.parseInt(currentURL.substring((last - y) + 1, last - x)) != lastCHAPTER)
		{
			c++;
			if(c > chapters)
				System.exit(-1);
		}
		lastCHAPTER = Integer.parseInt(currentURL.substring((last - y) + 1, last - x));
		if(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1)
			fdownload(address, ot);
		else
			System.err.println((new StringBuilder("Could not figure out local file name for ")).append(address).toString());
	}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1