26 Nisan 2012 Perşembe

Creating JSP Web Application in Netbeans

1. In start page, click "Install Plugins".

2. Under Available Plugins, search for "Java Web Applications". Select it.
When you select, it automatically selects its dependencies.

3. Click Install.

4. File > New Project > Web > JSP

5. Name your project as HelloWeb.
















6. Click Next. Specify your server location.
I used Tomcat. Set its root directory.

7. Change body as
<body>
<h1>Hello Web !</h1>
</body>

8. Finally, Run index.jsp


How to extract the regions with different colors from the input image

I developed a MATLAB function color_extract that extracts the regions with different colors from
the input image using a color model different than RGB. The purpose of it is to use different color models.




Processing of Color Images:

1. Convert to another color model YIQ, HSV, etc.
(You can use matlab functions ex: rgb2hsv)
2. Process the image, make changes.
3. Then convert it back to RGB.
(You can use matlab functions ex: hsv2rgb)












Note: I used HSV. To obtain Hue values easily, you can use MS Paint by clicking "EditColors".























Download Code

25 Nisan 2012 Çarşamba

Install Apache Tomcat

1. Before downloading Tomcat, You must have the JDK installed, and be sure that the environment variables are set.
(JAVA_HOME and CLASSPATH)

2. download Tomcat !

3. Unzip the zip file anywhere.

4. After unzipping the file, navigate to the "bin" directory and start Tomcat by running the startup.bat file.

5. After starting Tomcat, open your browser and type the following URL: http://localhost:8080.
(Tomcat uses port 8080 by default)

Here it is!


ref

20 Nisan 2012 Cuma

Connect Four Game

"Connect Four" oyununu mutlaka oynamışsınızdır.
Oynamayanlar için : Connect Four Game
(Programa karşı oynuyorsunuz.Programda yapay zeka kullanıldı.)



















Download Code

16 Nisan 2012 Pazartesi

İlk Android Projem :)

Write a program which converts temperature degrees between Fahrenheit (F) and Celsius (C) in both directions.

1. Create Project

Select File → New → Other → Android → Android Project and create the Android project "de.vogella.android.temperature". Enter the following.




Press "Finish". This should create the following directory structure.

2. Create attributes
Android allows you to create static attributes, e.g. Strings or colors. These attributes can for example be used in your XML layout files or referred to via Java source code.

Select the file "res/values/string.xml" and press the "Add" button. Select "Color" and enter "myColor" as the name and "#3399CC" as the value.


Add the following "String" attributes. String attributes allow the developer to translate the application at a later point.

Name           Value
celsius        to Celsius
fahrenhei    to Fahrenheit
calc              Calculate


Switch to the XML representation and validate that the values are correct.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Convert!</string>
<string name="app_name">Temperature Converter</string>
<color name="myColor">#3399CC</color>
<string name="myClickHandler">myClickHandler</string>
<string name="celsius">to Celsius</string>
<string name="fahrenheit">to Fahrenheit</string>
<string name="calc">Calculate</string>
</resources>
3. Add Views

Select "res/layout/main.xml" and open the Android editor via a double-click. This editor allows you to create the layout via drag and drop or via the XML source code. You can switch between both representations via the tabs at the bottom of the editor. For changing the position and grouping elements you can use the Eclipse "Outline" view.

The following shows a screenshot of the "Palette" view from which you can drag and drop new user interface components into your layout. Please note that the "Palette" view changes frequently so your view might be a bit different.


You will now create your new layout.

Right-click on the existing text object “Hello World, Hello!” in the layout. Select "Delete" from the popup menu to remove the text object. Then, from the “Palette” view, select Text Fields and locate "Plain Text". Drag this onto the layout to create a text input field. All object types in the section "Text Fields” derive from the class "EditText", they just specify via an additional attribute which text type can be used.

Afterwards select the Palette section "Form Widgets" and drag a “RadioGroup” object onto the layout. The number of radio buttons added to the radio button group depends on your version of Eclipse. Make sure there are two radio buttons by deleting or adding radio buttons to the group.




From the Palette section Form Widgets, drag a Button object onto the layout.

The result should look like the following.

4. Edit View properties
If you select a user interface component (an instance of View ), you can change its properties via the Eclipse "Properties" view. Most of the properties can be changed via the right mouse menu. You can also edit properties of fields directly in XML. Changing properties in the XML file is much faster, if you know what you want to change. But the right mouse functionality is nice, if you are searching for a certain property.

Open your file "main.xml". The EditText control shows currently a default text. We want to delete this initial text in the XML code. Switch to the XML tab called "main.xml" and delete the android:text="EditText" property from the EditText part. Switch back to the "Graphical Layout" tab and check that the text is removed.

Use the right mouse click on the first radio button to assign the "celsius" String attribute to its "text" property. Assign the "fahrenheit" string attribute to the second radio button.


From now on, I assume you are able to use the properties menu on user interface components. You can always either edit the XML file or modify the properties via right mouse click.

Set the property "Checked" to true for the first RadioButton.

Assign "calc" to the text property of your button and assign "myClickHandler" to the "onClick" property.

Set the "Input type" property to "numberSigned" and "numberDecimal" on your EditText.

All your user interface components are contained in a LinearLayout. We want to assign a background color to this LinearLayout. Right-click on an empty space in Graphical Layout mode, then select Other Properties → All by Name → Background. Select “Color” and then select "myColor" "in the list which is displayed.



















5. Change the Activity source code

package de.vogella.android.temperature;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class ConvertActivity extends Activity {
private EditText text;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (EditText) findViewById(R.id.editText1);

}

// This method is called at button click because we assigned the name to the
// "On Click property" of the button
public void myClickHandler(View view) {
switch (view.getId()) {
case R.id.button1:
RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
if (text.getText().length() == 0) {
Toast.makeText(this, "Please enter a valid number",
Toast.LENGTH_LONG).show();
return;
}

float inputValue = Float.parseFloat(text.getText().toString());
if (celsiusButton.isChecked()) {
text.setText(String
.valueOf(convertFahrenheitToCelsius(inputValue)));
celsiusButton.setChecked(false);
fahrenheitButton.setChecked(true);
} else {
text.setText(String
.valueOf(convertCelsiusToFahrenheit(inputValue)));
fahrenheitButton.setChecked(false);
celsiusButton.setChecked(true);
}
break;
}
}

// Converts to celsius
private float convertFahrenheitToCelsius(float fahrenheit) {
return ((fahrenheit - 32) * 5 / 9);
}

// Converts to fahrenheit
private float convertCelsiusToFahrenheit(float celsius) {
return ((celsius * 9) / 5) + 32;
}
}

6. Start Project

select Run-As → Android Application

ref

Google Play

Google offers the "Google Play" service.
Google hosts Android applications and the Google Play application allows to install new Android application on an Android device. Google Play used to be called "Android Market".

ref

Android Operation System

Android is an operating system based on Linux with a Java programming interface.

The Android Software Development Kit (Android SDK) provides all necessary tools to develop Android applications. This includes a compiler, debugger and a device emulator, as well as its own virtual machine to run Android programs.

Android is currently primarily developed by Google.

Android allows background processing, provides a rich user interface library, supports 2-D and 3-D graphics using the OpenGL libraries, access to the file system and provides an embedded SQLite database.

Android applications consist of different components and can re-use components of other applications, if these applications declare their components as available. This leads to the concept of a task in Android; an application can re-use other Android components to archive a task.

For example you can write an application which integrates a map component and a camera component to archive a certain task.

ref

14 Nisan 2012 Cumartesi

Online Sunum - Prezi


powerpoint ve open office'in tatsiz sunumlarindan sikilanlar icin son derece güzel bir sunum uygulamasi. sunumunuzu platform bagimsiz olarak online hazirlayip sunabiliyorsunuz.klasik sunum yöntemlerinden farkli, zoom in ve out'a dayali, göze pek hoş görünen bir tarzi var. göstermek istediklerinizi büyük bir yüzey üzerine daginik ama birbirleriyle baglantili bicimde serpistirip, sonra interaktif olarak hoplaya ziplaya gösterebiliyorsunuz.

prezi

wiki prezi

Masaüstü videosu çeken program

Sunumda video kullanmak genelde artı puan kazandırır :)

ayrıca yaptığınız bir programın nasıl çalıştığını da adım adım gösterebilirsiniz.

Programın Tanıtımı :

HyperCam uygulaması Windows ekranını avi (Audio-Video Interleaved) olarak kaydeder. Sesi ise sizin sistem mikrofonuzla eğer isterseniz kaydedebilirsiniz. Kaydettiğiniz video üzerine istediğiniz yazıyı da ekleyebilirsiniz. Programın en iyi yanı işiniz için sunumlar, tanıtım videoları veya istediğiniz herhangi bir video görüntüsünü oluşturabilmenizdir.


download

ref

13 Nisan 2012 Cuma

How to create an AVD for Android 4.0

Android 4.0 SDK yı kurduktan sonra virtual bir device eklemek istediğimde şöyle bir hata ile karşılaştım:

"Unable to find a 'userdata.img' file for ABI armeabi to copy into the AVD folder."

If you look in the "Android SDK Manager" in the "Android 4.0 (API 14)" section you'll see a few packages. One of these is named "ARM EABI v7a System Image".

This is what you need to download in order to create an Android 4.0 virtual device:













ref

6 Nisan 2012 Cuma

Sending Email With Images in a HTML Table Through Java



Mailinizi html şeklinde tasarlayın ve sonra bu html i message ınıza set edin.

message.setContent(your html);














import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class MailSender {

/* */
private Properties props = new Properties();

/* */
private Session session;

/* */
private InternetAddress sdriveMail;

/**
*
*/
public MailSender() {
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("info.sdrive","şifre");
}
});

try {
sdriveMail = new InternetAddress("info.sdrive@gmail.com");
} catch (AddressException e) {

}

}

/**
*
* @param mailAddress
* @param userName
* @param nickName
*/
public void sendWelcomeMail(String mailAddress, String userName, String nickName){
try {

Message message = new MimeMessage(session);
message.setFrom(sdriveMail);
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(mailAddress));
message.setSubject("Welcome to SDrive!");
message.setContent
("<html><body><table border = \"3\" width = \"800\"><tr align=\"center\"><td><img src=\"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQRh7AYO4dETB_gzAhFuqyFhFYapzZ7trft3bb9TZCThbLG0lIjrOJXhz6j5EXshqMBbK1NkYQTeY7MAj6yFpOfZWaBq7iJg9XbaxY3KdBJnRsDi3PXamWhWxqt8PqtMtfiwpwMrZYdZfd/s320/t2.png\">"
+ "</td></tr><tr><td height = \"100\" ><h3>Dear Sdrive user,</h3>" + "Welcome to SDrive!" +
" Thank you for registering with Sdrive!</td></tr><tr><td height = \"150\">" +
"<p>Your account information:</p>" +
"<p>Name: " + userName +
"</p><p>User Name: "+ nickName +
"</p><p>Email: "+ mailAddress + "</p><br /><br /><p>Copyright &copy; 2012 SDrive. All rights reserved.</p></td></tr></table></body></html>",
"text/html");

Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {

}
}



public static void main(String[] args) {
MailSender mail = new MailSender();
mail.sendWelcomeMail("baharcglr@gmail.com", "Bahar Çaglar", "baharcaglar");
}
}

5 Nisan 2012 Perşembe

Log4j vs java.util.logging API

You have seen logging levels in log4j they have optimized number of java logging level and each of them fully describes what it does. Another flexibility of log4j is that you can change logging level of your java application without restarting your java application, by the way this you can do in java.util.logging API by using JMX if you have implemented that.
Log4j also provides flexibility to set logging level based on per class in its configuration file log4j.xml. You can either use log4j.properties file or log4j.xml for configuring java logging in your application while using log4j for logging in java. Also log4j is thread-safe. Log4j components are designed to be used in heavily multithreaded systems. On the other hand Formatter and Appender facility of java.util.logging API quite useful especially Formatter allows you to format java logging output as you want for logging in Java.

4 Nisan 2012 Çarşamba

JUnit 4

1. @Test
Mark your test cases with @Test annotations. You don’t need to prefix your test cases with “test”. In addition, your class does not need to extend from “TestCase” class.
@Test
public void addition() {
assertEquals(12, simpleMath.add(7, 5));
}

@Test
public void subtraction() {
assertEquals(9, simpleMath.substract(12, 3));
}

2. @Before and @After
Use @Before and @After annotations for “setup” and “tearDown” methods respectively. They run before and after every test case.
@Before
public void runBeforeEveryTest() {
simpleMath = new SimpleMath();
}

@After
public void runAfterEveryTest() {
simpleMath = null;
}

3. @BeforeClass and @AfterClass
Use @BeforeClass and @AfterClass annotations for class wide “setup” and “tearDown” respectively. Think them as one time setup and tearDown. They run for one time before and after all test cases.
@BeforeClass
public static void runBeforeClass() {
// run for one time before all test cases
}

@AfterClass
public static void runAfterClass() {
// run for one time after all test cases
}

4.Exception Handling
Use “expected” paramater with @Test annotation for test cases that expect exception. Write the class name of the exception that will be thrown.
@Test(expected = ArithmeticException.class)
public void divisionWithException() {
// divide by zero
simpleMath.divide(1, 0);
}

5. @Ignore
Put @Ignore annotation for test cases you want to ignore. You can add a string parameter that defines the reason of ignorance if you want.

@Ignore(“Not Ready to Run”)
@Test
public void multiplication() {
assertEquals(15, simpleMath.multiply(3, 5));
}


6. Timeout
Define a timeout period in miliseconds with “timeout” parameter. The test fails when the timeout period exceeds.
@Test(timeout = 1000)
public void infinity() {
while (true)
;
}


7. New Assertions
Compare arrays with new assertion methods. Two arrays are equal if they have the same length and each element is equal to the corresponding element in the other array; otherwise, they’re not.
public static void assertEquals(Object[] expected, Object[] actual);
public static void assertEquals(String message, Object[] expected, Object[] actual);

@Test
public void listEquality() {
List expected = new ArrayList();
expected.add(5);

List actual = new ArrayList();
actual.add(5);

assertEquals(expected, actual);
}


8. JUnit4Adapter
Run your Junit 4 tests in Junit 3 test runners with Junit4Adapter.
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(SimpleMathTest.class);
}

ref

Java - Eclipse Generate JavaDoc

1.Listed below is a Javadoc comment style used to generate a Javadoc.
Use following comment style to generate a Javadoc.






















2. Click on projects link and choose ” Generate Javadoc ” option.





















3.Now a window will be opened where you can select Java Projects or their underlying resources for which JavaDoc needs to be generated. Several other options are also there where user can select any of them as per the need.Here user can select whether to generate JavaDoc for public/private API’s etc.





















4. Click “Finish” Javadoc will be generated. If you select option of opening index file in browser then after generation of Javadoc you will find ” index.htm ” of Javadoc in your default Web Browser. On console you can see progress of JavaDoc Generation.


2 Nisan 2012 Pazartesi

java open frame in the center of window

/** Put frame at center of screen. **/
Ben kendi frame imin boyutuna göre ayarladım width i 3'e height ı 7 ye böldüm.
Frame in left top coordinatına bu değeri attım. Frame size ınıza göre bunu değiştirebilirsiniz
void centerFrame (JFrame f) {
// Need the toolkit to get info on system.
Toolkit tk = Toolkit.getDefaultToolkit ();

// Get the screen dimensions.
Dimension screen = tk.getScreenSize ();

// And place it in center of screen.
int lx = (int) (screen.getWidth () /3);
int ly = (int) (screen.getHeight ()/7);
f.setLocation (lx,ly);
} // centerFrame

How to List all files in a directory

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public List getAllFilesInDirectory(String directory) {

String files;
File folder = new File(directory);
File[] listOfFiles = folder.listFiles();
List allFiles = new ArrayList<>();

for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
//System.out.println(files);
allFiles.add(files);
}
}
return allFiles;
}