Java Swing – Set JTextField Text Color

import javax.swing.JTextField;
import javax.swing.JFrame;

import java.awt.Color;
import java.awt.FlowLayout;

public class SetJTextFieldTextColor {

	public static void main(String[]args) {

		//Create text field using JTextField
		JTextField textField = new JTextField(10);

		//Create JFrame with title (Set JTextField text color)
		JFrame frame = new JFrame("Set JTextField text color");

		//Set JFrame layout to FlowLayout
		frame.setLayout(new FlowLayout());

		//Set color base on RGB
		//You can get RGB value for your color at "Color picker" at above
		//R=255
		//G=0
		//B=0
		Color color = new Color(255,0,0);

		//Set JTextField text color to color that you choose
		textField.setForeground(color);

		//Add JTextField into JFrame
		frame.add(textField);

		//Set default close operation for JFrame
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		//Set JFrame size
		frame.setSize(500,300);

		//Make JFrame visible
		frame.setVisible(true);
	}
}

Java – Get List of Files from FTP Server

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.io.FileUtils;
import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		FTPClient client = new FTPClient();

		client.connect("ftp.domain.com");
		client.login("admin", "secret");

		String[] names = client.listNames();
		for (String name : names) {
			System.out.println("Name = " + name);
		}

		FTPFile[] ftpFiles = client.listFiles();
		for (FTPFile ftpFile : ftpFiles) {
			// Check if FTPFile is a regular file
			if (ftpFile.getType() == FTPFile.FILE_TYPE) {
				System.out.println("FTPFile: " + ftpFile.getName() + "; "
						+ FileUtils.byteCountToDisplaySize(ftpFile.getSize()));
			}
		}
		client.logout();
		client.disconnect();
	}

}

Java – Extract links from HTML page

import java.io.FileReader;
import java.util.ArrayList;

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML.Attribute;
import javax.swing.text.html.HTML.Tag;
import javax.swing.text.html.HTMLEditorKit.ParserCallback;
import javax.swing.text.html.parser.ParserDelegator;

public class Main {

	public final static void main(String[] args) throws Exception {
		final ArrayList<String> list = new ArrayList<String>();

		ParserDelegator parserDelegator = new ParserDelegator();
		ParserCallback parserCallback = new ParserCallback() {
			public void handleText(final char[] data, final int pos) {
			}

			public void handleStartTag(Tag tag, MutableAttributeSet attribute, int pos) {
				if (tag == Tag.A) {
					String address = (String) attribute.getAttribute(Attribute.HREF);
					list.add(address);
				}
			}

			public void handleEndTag(Tag t, final int pos) {
			}

			public void handleSimpleTag(Tag t, MutableAttributeSet a, final int pos) {
			}

			public void handleComment(final char[] data, final int pos) {
			}

			public void handleError(final java.lang.String errMsg, final int pos) {
			}
		};
		parserDelegator.parse(new FileReader("a.html"), parserCallback, false);
		System.out.println(list);
	}

}

Page 1 of 3123