Search

'분류 전체보기'에 해당되는 글 566건

  1. 2014.01.24 JAVA 채팅 프로그램 export zip 1
  2. 2014.01.22 JAVA DML
  3. 2014.01.21 JAVA 채팅 프로그램
  4. 2014.01.21 CPP 실습예제
  5. 2014.01.21 CPP GeometricObject
  6. 2014.01.20 JAVA 채팅 예제 #2
  7. 2014.01.20 JAVA 채팅 Server 예제 #1
  8. 2014.01.20 JAVA 채팅 Client 예제 #1
  9. 2014.01.19 Android GoogleMap API V2
  10. 2014.01.17 JAVA FIle 실습 #1

JAVA 채팅 프로그램 export zip

Programming/JAVA,JSP 2014. 1. 24. 15:32 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

JAVA 채팅 프로그램 export zip





JavaChatting20140124.zip




JavaChatting20140124 #2.zip





JavaChatting20140124 #3.zip





JavaChatting20140124 #4 대화명 변경가능.zip


'Programming > JAVA,JSP' 카테고리의 다른 글

String to int, int to String  (0) 2014.06.07
이클립스 라인넘버 표시  (1) 2014.03.07
JAVA DML  (0) 2014.01.22
JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 예제 #2  (0) 2014.01.20

JAVA DML

Programming/JAVA,JSP 2014. 1. 22. 16:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

INSERT INTO books (title, publisher, year, price)

  VALUES(‘Operating System Concepts’, ‘Wiley’, ‘2003’, 30700);

INSERT INTO books (title, publisher, year, price)

  VALUES(‘Head First PHP and MYSQL’, ‘OReilly’, ‘2009’, 58000);

INSERT INTO books (title, publisher, year, price)

  VALUES(‘C Programming Language’, ‘Prentice-Hall’, ‘1989’, 35000);

INSERT INTO books (title, publisher, year, price)

  VALUES(‘Head First SQL’, ‘OReilly’, ‘2007’, 43700);

'Programming > JAVA,JSP' 카테고리의 다른 글

이클립스 라인넘버 표시  (1) 2014.03.07
JAVA 채팅 프로그램 export zip  (1) 2014.01.24
JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Server 예제 #1  (0) 2014.01.20

JAVA 채팅 프로그램

Programming/JAVA,JSP 2014. 1. 21. 17:38 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

서버




import java.io.IOException;

import java.net.ServerSocket;

import java.net.Socket;


import javax.swing.DefaultListModel;

import javax.swing.JFrame;

import javax.swing.JList;


class MyFrame extends JFrame {

DefaultListModel listModel ;

MyFrame(DefaultListModel listModel){

this.listModel = listModel;

setSize(600, 400);

setDefaultCloseOperation(this.EXIT_ON_CLOSE);


JList list = new JList(listModel);


add(list);


setVisible(true);

}

}


public class Server {

public static DefaultListModel listModel = new DefaultListModel();

public static void main(String[] args) {

try {


ServerSocket ss = new ServerSocket(5555);

Socket s;


MyFrame mf = new MyFrame(listModel);

while (true) {


s = ss.accept();


listModel.addElement( s.getInetAddress() );

System.out.println("입장 : " + s.getInetAddress());

PerClientThread pc = new PerClientThread();

pc.s = s;

pc.start();


}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}





import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

public class PerClientThread extends Thread {
public static ArrayList<PrintWriter> printWriterList = new ArrayList<PrintWriter>();
public Socket s;

@Override
public void run() {
PrintWriter out = null;
BufferedReader in = null;
try {
out = new PrintWriter(s.getOutputStream(), true);
printWriterList.add(out);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
{
System.out.println( s.getInetAddress() + " : " +  inputLine);
for( int i = 0 ; i < printWriterList.size() ; i++ )
{
printWriterList.get(i).println(inputLine);
}
}
Server.listModel.removeElement(s.getInetAddress());
in.close();
out.close();
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("발생자 : " + s.getInetAddress());
e.printStackTrace();
Server.listModel.removeElement(s.getInetAddress());
}
Server.listModel.removeElement(s.getInetAddress());
}

}







클라이언트


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Client {
static JTextField textField;
static JTextArea textArea;
static PrintWriter out;
static BufferedReader in;

public static void main(String[] args) {
try {
Socket s = new Socket("115.20.247.170", 5555);

out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
JFrame f = new JFrame("채팅");
f.setSize(600, 400);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
textArea = new JTextArea();
JScrollPane sp = new JScrollPane(textArea);
textField = new JTextField(10);
textField.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
out.println("TSC : " + textField.getText());
textField.setText("");
}
}

);
f.add(textField, BorderLayout.SOUTH);
f.add(sp, BorderLayout.CENTER);
f.setVisible(true);
ReceiveMSG rMSG = new ReceiveMSG();
rMSG.textArea = textArea;
rMSG.in = in;
rMSG.start();

} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}






import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.io.BufferedReader;
import java.io.IOException;

import javax.swing.JTextArea;

public class ReceiveMSG extends Thread {
public JTextArea textArea;

public BufferedReader in;

@Override
public void run() {

while (true) {
try {
String msg;
msg = in.readLine();
textArea.setText(textArea.getText()+ "\n" + msg);
textArea.setCaretPosition(textArea.getDocument().getLength());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

}


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 프로그램 export zip  (1) 2014.01.24
JAVA DML  (0) 2014.01.22
JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20

CPP 실습예제

실습과제 모음 2014. 1. 21. 14:45 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

using namespace std;

class Line

{

public:

double startX;

double startY;

double endX;

double endY;

};


class GeometricObject

{

public:

Line line1;

Line line2;


GeometricObject()

{

line1.startX = 0;

line1.startY = 0;

line1.endX = 0;

line1.endY = 0;

line2.startX = 0;

line2.startY = 0;

line2.endX = 0;

line2.endY = 0;

}

GeometricObject(Line a, Line b)

{

line1 = a;

line2 = b;

}

void setLine1(Line a)

{

line1 = a;

}

void setLine2(Line a)

{

line2 = a;

}

Line getLine1()

{

return line1;

}

Line getLine2()

{

return line2;

}

virtual double AreaCalculation() = 0;

virtual double Compute() = 0;

};

class Isosceles : public GeometricObject

{

public:

double area;

double side;


Isosceles()

{

line1.startX = 0;

line1.startY = 0;

line1.endX = 0;

line1.endY = 0;

line2.startX = 0;

line2.startY = 0;

line2.endX = 0;

line2.endY = 0;

area = 0;

side = 0;

}

Isosceles(Line a , Line b)

{

line1 = a;

line2 = b;

area = 0;

side = 0;

}

double AreaCalculation( )

{


return 0.0;

}

double Compute( )

{

return 0.0;

}

void setArea(double a)

{

area = a;

}

void setSide(double a)

{

side = a;

}

double getArea()

{

return area;

}

double getSide()

{

return side;

}

};


int main()

{

Line l1;

l1.startX = 15;

l1.startY = 0;

l1.endX = 15;

l1.endY = 30;

Line l2;

l2.startX = 0;

l2.startY = 30;

l2.endX = 30;

l2.endY = 30;

Isosceles is(l1,l2);

cout << is.AreaCalculation() << endl;

return 0;

}



'실습과제 모음' 카테고리의 다른 글

별 찍기 예제 #3  (0) 2014.03.29
별 찍기 예제 #2  (0) 2014.03.29
CPP GeometricObject  (0) 2014.01.21
cpp 실습  (0) 2014.01.15
CPP 실습  (0) 2014.01.15

CPP GeometricObject

실습과제 모음 2014. 1. 21. 14:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <iostream>

using namespace std;

class Line

{

public:

double startX;

double startY;

double endX;

double endY;

}


class GeometricObject

{

Line line1;

Line line2;


GeometricObject()

{

line1.startX = 0;

line1.startY = 0;

line1.endX = 0;

line1.endY = 0;

line2.startX = 0;

line2.startY = 0;

line2.endX = 0;

line2.endY = 0;

}

GeometricObject(Line a, Line b)

{

line1 = a;

line2 = b;

}

void setLine1(Line a)

{

line1 = a;

}

void setLine2(Line a)

{

line2 = a;

}

Line getLine1()

{

return line1;

}

Line getLine2()

{

return line2;

}

double AreaCalculation() = 0;

double RoundCalculation() = 0;

}

int main()

{

Line l1;

Line l2;

GeometricObject go(l1, l2);

return 0;

}

'실습과제 모음' 카테고리의 다른 글

별 찍기 예제 #2  (0) 2014.03.29
CPP 실습예제  (0) 2014.01.21
cpp 실습  (0) 2014.01.15
CPP 실습  (0) 2014.01.15
JAVA 실습 과제 2014 01 02  (0) 2014.01.02

JAVA 채팅 예제 #2

Programming/JAVA,JSP 2014. 1. 20. 17:48 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.IOException;

import java.io.ObjectInputStream;

import java.net.ServerSocket;

import java.net.Socket;


public class Server {

public static void main(String[] args) {

try {

ServerSocket ss = new ServerSocket(5555);

Socket s;

while (true) {


s = ss.accept();


System.out.println("입장 : " + s.getInetAddress());

PerClientThread pc = new PerClientThread();

pc.s = s;

pc.start();


}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}







import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

public class PerClientThread extends Thread {
public static ArrayList<PrintWriter> printWriterList = new ArrayList<PrintWriter>();
public Socket s;

@Override
public void run() {
PrintWriter out = null;
BufferedReader in = null;
try {
out = new PrintWriter(s.getOutputStream(), true);

printWriterList.add(out);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
{
System.out.println( s.getInetAddress() + " : " +  inputLine);
for( int i = 0 ; i < printWriterList.size() ; i++ )
{
printWriterList.get(i).println(inputLine);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println("발생자 : " + s.getInetAddress());
e.printStackTrace();
}
}

}









import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

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

public class Client {
static JTextField textField;
static JTextArea textArea;
static PrintWriter out;
static BufferedReader in;

public static void main(String[] args) {
try {
Socket s = new Socket("115.20.247.170", 5555);

out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
JFrame f = new JFrame("채팅");
f.setSize(600, 400);
f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
textArea = new JTextArea();
textField = new JTextField(10);
textField.addActionListener(
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
out.println(textField.getText());
textField.setText("");
}
}

);
f.add(textField, BorderLayout.SOUTH);
f.add(textArea, BorderLayout.CENTER);
f.setVisible(true);
ReceiveMSG rMSG = new ReceiveMSG();
rMSG.textArea = textArea;
rMSG.in = in;
rMSG.start();

} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}







import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.swing.JTextArea;

public class ReceiveMSG extends Thread {
public JTextArea textArea;

public BufferedReader in;

@Override
public void run() {

while (true) {
try {
String msg;
msg = in.readLine();
textArea.setText(textArea.getText()+ "\n" + msg);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}

}


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA DML  (0) 2014.01.22
JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17

JAVA 채팅 Server 예제 #1

Programming/JAVA,JSP 2014. 1. 20. 17:28 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.io.IOException;

import java.io.ObjectInputStream;

import java.net.ServerSocket;

import java.net.Socket;


public class Server {

public static void main(String[] args) {

try {

ServerSocket ss = new ServerSocket(5555);

Socket s;

while (true) {


s = ss.accept();


System.out.println("입장 : " + s.getInetAddress());

PerClientThread pc = new PerClientThread();

pc.s = s;

pc.start();


}


} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}


}

}



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class PerClientThread extends Thread {
public Socket s;

@Override
public void run() {
PrintWriter out = null;
BufferedReader in = null;
try {
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null)
{
System.out.println( s.getInetAddress() + " : " +  inputLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}


'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 프로그램  (0) 2014.01.21
JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17

JAVA 채팅 Client 예제 #1

Programming/JAVA,JSP 2014. 1. 20. 17:27 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.BorderLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.IOException;

import java.io.PrintWriter;

import java.net.Socket;

import java.net.UnknownHostException;

import java.util.Scanner;


import javax.swing.JFrame;

import javax.swing.JTextArea;

import javax.swing.JTextField;




public class Client {

static JTextField textField;

static JTextArea textArea;

static PrintWriter out;

public static void main(String[] args) {

try {

Socket s = new Socket("115.20.247.170",5555);


out = new PrintWriter(s.getOutputStream(), true);


JFrame f = new JFrame("채팅");

f.setSize(600, 400);

f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);

textArea = new JTextArea();

textField = new JTextField(10);

textField.addActionListener(


new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

out.println(textField.getText());

}

}

);

f.add(textField, BorderLayout.SOUTH);

f.add(textArea , BorderLayout.CENTER);

f.setVisible(true);

} catch (UnknownHostException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}



'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 예제 #2  (0) 2014.01.20
JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA FIle 실습 #1  (0) 2014.01.17
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16

Android GoogleMap API V2

Programming/Android 2014. 1. 19. 11:50 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

안드로이드 맵에 검색창 띄워서 검색하기



Android Geocoding – Showing User Input Location on Google Map Android API V2



In this article, we will create an Android application which facilitates users to input street address in an EditText and on clicking the find button, application draws corresponding location marker on the Google Map Android API v2 using Google’s Geocoder API.

This application is an upgraded version of the application discussed in the article titled “Android Geocoding – Showing User Input Location on Google Map” where the location is shown in Google Map Android API v1.

This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 ) and is tested in a real Android Phone with Android 2.3.6  ( GingerBread ).


1. Download and configure Google Play Services Library in Eclipse

Please follow the given below link to setup Google Play Service library in Eclipse.

http://developer.android.com/google/play-services/setup.html


2. Create a new Android Application Project namely “LocationGeocodingV2″

Create new Android application project

Figure 1 : Create new Android application project


3. Configure Android Application Project

Configure Android Application Project

Figure 2 : Configure Android Application Project


4. Design Application Launcher Icon

Design Application Launcher Icon

Figure 3 : Design Application Launcher Icon


5. Create a blank activity

Create a blank activity

Figure 4 : Create a blank activity


6. Enter Main Activity Details

Enter Main Activity Details

Figure 5 : Enter Main Activity Details


7. Link to Google Play Service Library

Link to Google Play Services Library

Figure 6 : Link to Google Play Services Library


8. Get the API key for Google Maps Android API v2

We need to get an API key from Google to use Google Maps in Android application. Please follow the given below link to get the API key for Google Maps Android API v2.

https://developers.google.com/maps/documentation/android/start


9. Add Android Support library to this project

By default, Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs. If it is not added, we can do it manually by doing the following steps :

  • Open Project Explorer by Clicking “Window -> Show View -> Project Explorer”
  • Right click this project
  • Then from popup window, Click “Android Tools -> Add Support Library “

10. Update the file AndroidManfiest.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?xml version="1.0" encoding="utf-8"?>
    package="in.wptrafficanalyzer.locationgeocodingv2"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
 
    <permission
        android:name="in.wptrafficanalyzer.locationgeocodingv2.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
 
    <uses-permission android:name="in.wptrafficanalyzer.locationgeocodingv2.permission.MAPS_RECEIVE"/>
 
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
 
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/>
 
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
 
        <activity
            android:name="in.wptrafficanalyzer.locationgeocodingv2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="YOUR_API_KEY"/>
    </application>
</manifest>

11. Update the layout file res/layout/activity_main.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >
 
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
 
        <Button
            android:id="@+id/btn_find"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/str_btn_find"
            android:layout_alignParentRight="true" />
 
        <EditText
            android:id="@+id/et_location"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="@string/hnt_et_location"
            android:layout_toLeftOf="@id/btn_find" />
 
    </RelativeLayout>
 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />
 
</LinearLayout>

12. Update the file res/values/strings.xml

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="app_name">LocationGeocodingV2</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="str_btn_find">Find</string>
    <string name="hnt_et_location">Enter location</string>
</resources>

13. Update the file src/in/wptrafficanalyzer/locationgeocodingv2/MainActivity.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package in.wptrafficanalyzer.locationgeocodingv2;
 
import java.io.IOException;
import java.util.List;
 
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
 
public class MainActivity extends FragmentActivity {
 
    GoogleMap googleMap;
    MarkerOptions markerOptions;
    LatLng latLng;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        SupportMapFragment supportMapFragment = (SupportMapFragment)
        getSupportFragmentManager().findFragmentById(R.id.map);
 
        // Getting a reference to the map
        googleMap = supportMapFragment.getMap();
 
        // Getting reference to btn_find of the layout activity_main
        Button btn_find = (Button) findViewById(R.id.btn_find);
 
        // Defining button click event listener for the find button
        OnClickListener findClickListener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Getting reference to EditText to get the user input location
                EditText etLocation = (EditText) findViewById(R.id.et_location);
 
                // Getting user input location
                String location = etLocation.getText().toString();
 
                if(location!=null && !location.equals("")){
                    new GeocoderTask().execute(location);
                }
            }
        };
 
        // Setting button click event listener for the find button
        btn_find.setOnClickListener(findClickListener);
 
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
 
    // An AsyncTask class for accessing the GeoCoding Web Service
    private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{
 
        @Override
        protected List<Address> doInBackground(String... locationName) {
            // Creating an instance of Geocoder class
            Geocoder geocoder = new Geocoder(getBaseContext());
            List<Address> addresses = null;
 
            try {
                // Getting a maximum of 3 Address that matches the input text
                addresses = geocoder.getFromLocationName(locationName[0], 3);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return addresses;
        }
 
        @Override
        protected void onPostExecute(List<Address> addresses) {
 
            if(addresses==null || addresses.size()==0){
                Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
            }
 
            // Clears all the existing markers on the map
            googleMap.clear();
 
            // Adding Markers on Google Map for each matching address
            for(int i=0;i<addresses.size();i++){
 
                Address address = (Address) addresses.get(i);
 
                // Creating an instance of GeoPoint, to display in Google Map
                latLng = new LatLng(address.getLatitude(), address.getLongitude());
 
                String addressText = String.format("%s, %s",
                address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                address.getCountryName());
 
                markerOptions = new MarkerOptions();
                markerOptions.position(latLng);
                markerOptions.title(addressText);
 
                googleMap.addMarker(markerOptions);
 
                // Locate the first location
                if(i==0)
                    googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
            }
        }
    }
}

14. Screenshot of the application in execution

Showing Street Address in Google Map Android API V2

Figure 7 : Showing Street Address in Google Map Android API V2


15. Download Source Code









출처 : http://wptrafficanalyzer.in/blog/android-geocoding-showing-user-input-location-on-google-map-android-api-v2/



'Programming > Android' 카테고리의 다른 글

Android 2014-03-01 GoogleMap V2 띄우기  (0) 2014.03.01
Android 반짝이는 화면  (0) 2014.02.22
viewpagertest  (0) 2014.01.14
Android FrameLayout 예제  (0) 2014.01.12
안드로이드 위치 기록, 위치 추적  (0) 2014.01.12

JAVA FIle 실습 #1

Programming/JAVA,JSP 2014. 1. 17. 17:36 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

package com.tistory.tansanc;


import java.awt.Color;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.io.ObjectOutputStream;


import javax.swing.JButton;

import javax.swing.JColorChooser;

import javax.swing.JFrame;

import javax.swing.JPanel;


class MyFrame extends JFrame {

private JButton button1;

private JButton button2;

private JPanel panel;


public MyFrame() {

this.setSize(300, 200);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.setTitle("이벤트 예제");

panel = new JPanel();

button1 = new JButton("색상선택");

button1.addActionListener(new MyListener());

panel.add(button1);

this.add(panel);

LoadFile();

this.setVisible(true);

}


private void LoadFile() {

// TODO Auto-generated method stub

ObjectInputStream oos = null;

try {

oos = new ObjectInputStream(

new FileInputStream("Color.bin"));

Color newColor = (Color)oos.readObject();

panel.setBackground(newColor);

oos.close();

} catch ( IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

} catch (ClassNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


private class MyListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if (e.getSource() == button1) {

JColorChooser colorChooser = 

new JColorChooser();

Color newColor =

colorChooser.showDialog(MyFrame.this,

"Hello",Color.red);

System.out.println(newColor);

panel.setBackground(newColor);

ObjectOutputStream oos = null;

try {

oos = new ObjectOutputStream(

new FileOutputStream("Color.bin"));

oos.writeObject(newColor);

oos.close();

} catch ( IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}


public class MyFrameTest2 {

public static void main(String[] args) {

MyFrame t = new MyFrame();

}

}



'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 채팅 Server 예제 #1  (0) 2014.01.20
JAVA 채팅 Client 예제 #1  (0) 2014.01.20
JAVA File 실습  (0) 2014.01.17
JAVA 공던지기 게임 완성  (0) 2014.01.16
JAVA 공던지기 게임  (0) 2014.01.16