星期二 四月 14, 2009

Quick Design "Calculator" with GUI Builder in NetBeans 6.5

During NetBeans 6.5,you can do the GUI design very quickly and it's very convenient for you to use.You can work out the project by just drafting the swing components.


Before get started,you should install NetBeans 6.5(6.7 Milestone 1/2/3 is  also okay) and JDK 6(or higher edition) on your computer.


This time I'd like to do a simple calculator with NetBeans 6.5.


First of all,just oepn NetBens 6.5,choose Javase,create a new java desktop application, name for your project and make it the main project.


After that,we can design the calculator by drifting the swing components ,here we use Jbutton for the number 1 to 9 ,and use textfield to display the result.Like below:


 


I put the sourcecode in the attachment,you can download it and run it on your computer.


However,this is just a simple application,contains four arithmetic operations(add,subtract,multiply,divide)and arithmetic point operations.Besides,with it ,you can continue your next calculation .Of course, you can do further developing with the existing one.


 Source code:http://blogs.sun.com/Chinese_Functional_CA/resource/src.rar


 

星期五 三月 06, 2009

How to do the interface embellishment and font setting in NetBeans 6.5


(1)Install the newest JDK


Pls download the Java SE Development Kit (JDK) 6 Update 10 or higher edition to supprot the antialiasing font better.


The JDK download link:http://java.sun.com/javase/downloads/index.jsp


(2)Install ClearType


ClearType Tuner PowerToy can be used ot adjust the Expert Settings of antialiasing font.With the help of it, you can make the font more boldfaced.



Download this software:http://www.microsoft.com/windowsxp/downloads/powertoys/xppowertoys.mspx


(3)Modify the start setting of NetBeans


 Open filw netbeans.conf  from the path C:\\Program Files\\NetBeans 6.5\\etc\\ and find the lines like below:




# Options used by NetBeans launcher by default, can be overridden by explicit # command line switches: netbeans_default_options=.....



Add –fontsize 12 –laf javax.swing.plaf.metal.MetalLookAndFeel to the parameter string of netbeans_default_options  ,then it looks like this:



(4)Modify the setting of  Java font


Open  C:\\Program Files\\Java\\jdk1.6.0_10\\jre\\lib ,Rename or delete the   fontconfig.98.bfc and fontconfig.98.properties.src two files.After that, Make a copy of  fontconfig.properties.src and save as  fontconfig.properties, then open the fontconfig.properties  with text editor .


The reason why modifying  the conf file is to display the Java Program with diffrent font when ie has both  Chinese and English strings. Like this belowing code:




/\*\*
\* 通过控件视图渲染结果 \* \* 对应的控件视图文件是 view/_controls/footer_control.php 。 \*/ $this->_renderBlock('footer', $return);



The Chinese part Use Song Ti and the English part use  Consolas, Here is the displaying  effect:


 


In order to achieve the above effect, it needs to modify three parts of the font file.


A:Defination of filename:Make sure the correspondence between  font name and the font filename;


B:The correspondence between  virtual font and actual font:Make sure which actual font is used to display


the specific virtual font;


C:Make sure which font can be used to display the strings.


The font filename can use the belowing format.You can also define your favorite font by yourself.But please should keep it in mind that the font  name can not be used in Chinese.Like below:




# filename. 字体名=字体文件名 filename.Consolas=CONSOLA.TTF filename.Consolas_Bold=CONSOLAB.TTF filename.Consolas_Italic=CONSOLAI.TTF filename.Consolas_Bold_Italic=CONSOLAZ.TTF



After defining the font name, we can specify the  correspondence between  virtual font and actual font.


For example:I make the default  monospaced (virtual font)specify to the newly defined  Consolas ,and



change the configuration as follows:


        monospaced.plain.alphabetic=Courier New
        monospaced.bold.alphabetic=Courier New Bold
        monospaced.italic.alphabetic=Courier New Italic
        monospaced.bolditalic.alphabetic=Courier New Bold Italic
       #
modified as



monospaced.plain.alphabetic=Consolas
monospaced.bold.alphabetic=Consolas Bold
monospaced.italic.alphabetic=Consolas Italic
monospaced.bolditalic.alphabetic=Consolas Bold Ttalic



Finally,make change for the font searching order .After modifing,it will search for English font first and Chinese font second.As there is no Chinese font style in the English font,so it is showed clearly when using different English and Chinese font.



        sequence.monospaced.GBK=chinese-ms936,alphabetic,dingbats,symbol
        sequence.monospaced.GB18030=chinese-gb18030,alphabetic,dingbats,symbol
        # Modified as
       sequence.monospaced.GBK=alphabetic,chinese-ms936,dingbats,symbol
       sequence.monospaced.GB18030=alphabetic,chinese-gb18030,dingbats,symbol


 


After finishing all the steps above, restart NetBeans,it  looks like more attractive. 


星期四 八月 07, 2008

Create RESTful Web Services in Netbeans

Representational
state transfer (REST) is a style of software architecture for distributed
hypermedia systems. The terms “representational state transfer” and “REST” were
introduced in 2000 in
the doctoral dissertation of Roy Fielding.
Now, with Netbeans, we could create a RESTful web
services application in Java from scratch easily.

[Read More]

星期一 六月 30, 2008

NetBeans Multi-Language Support

NetBeans has strong ability with in multi-language support.


After installed, it looks like in Simplified Chinese only. In fact, you can easily switch it to English/Japanese version by a little change of shortcut command line. You need not install other package or plugin.

[Read More]

星期二 五月 06, 2008

Install NetBeans 6.1 on OpenSolaris 2008.05

IPS (Image Packaging System)


1. Choose menu on the left top "System" - "Administration" - "Package Manager". Press "Reload" button in the toolbar to refresh the package list.

2. Input "netbeans" in the text filed under the toolbar, and press "Enter". Select your favorite version of NetBeans in the list, and press "Install/Update" button.

3. When "Install/Update Confirmation" window pops up, please check "package dependencies". And press "Next" to start download. The NetBeans will be installed automatically.


Traditional Install


1. Download JDK 1.6.0u6 for Solaris x86/x64 file: jdk-6u6-solaris-i586.sh & NetBeans for Solaris x86/x64 file: netbeans-6.1-solaris-x86.sh



2. Setup JDK: Open "Terminal", switch to "root" with command "# su". Copy JDK setup file to /usr/jdk/, and run:
# cp jdk-6u6-solaris-i586.sh /usr/jdk/
# ./jdk-6u6-solaris-i586.sh

3. Setup NetBeans IDE 6.1: Open "Terminal", switch to "root" with command "# su". Run setup file:
# ./netbeans-6.1-solaris-x86.sh
With setup wizard, next and next. :-)
Note: Select JDK directory: /usr/jdk/jdk1.6.0_06/

4. Logout current user, login again. You can find "NetBeans IDE 6.1" in the "Applications" menu.


Resource



星期一 四月 21, 2008

Google Maps on Rails with NetBeans (Part Two)

Author: Gao Ang

Once we get the Google
Maps in our browser, we could see two point markers that we added in the final
page. Now we take a glace at the JavaScript code which generate by our Rails
application:

<html>

<head>

  <title>Map demo</title>

 

<script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAj5cpJ2swzFT77RVZXuP73BTX2XchcwgyHzp4Xo0DHRAzt2aLjhSg2ymVlJvVjBa7kWNgtqU8xxwIAQ'
type='text/javascript'></script>

</head>

<body id="map">

    <div id="main">

      <h1>Add New Location</h1>

<hr />

 

<script type="text/javascript">

var gmaps;

 

var location_3;

function location_3_infowindow_function(){

  location_3.openInfoWindowHtml("")

}

var location_4;

function location_4_infowindow_function(){

  location_4.openInfoWindowHtml("")

}

function initialize_gmap_gmaps() {

if (!GBrowserIsCompatible()) return
false;

gmaps = new GMap2(document.getElementById("gmaps"));

// initialization the center point of our map

gmaps.setCenter(new GLatLng(37.79, -122.4), 14);

  // set the default
type of the map

  gmaps.setMapType(G_NORMAL_MAP);

  // add control bar
for the map

  gmaps.addControl(new GLargeMapControl());

  gmaps.addControl(new GScaleControl());

  // create every
markers from the array @markers

  location_3 = new GMarker(new GLatLng(37.792528, -122.393981));

// add listener on our map

  GEvent.addListener(location_3, "click", function() {location_3_infowindow_function()});

    // add user
marker to the map

    gmaps.addOverlay(location_3);
 
  location_4 = new GMarker(new GLatLng(37.794391, -122.394831));

  GEvent.addListener(location_4, "click", function() {location_4_infowindow_function()});

    gmaps.addOverlay(location_4);

}

 

if (typeof window.onload != 'function')

  window.onload = initialize_gmap_gmaps;

else {

  old_before_cartographer_gmaps
= window.onload;

  window.onload = function() {

    old_before_cartographer_gmaps();

    initialize_gmap_gmaps();

  }

}

</script>

<div id="gmaps" style="width: 600px; height: 400px;"></div>

</div>

</body>

</html>

 

In the final page, Rails plugin
Cartographer help
us to generate most of our Google Maps API code. And then mark our location in
the final map.

After the above work, let’s
make some supplement for our gmaps application. We will create a form and let
user add the address in the page with the auto-geocoding provided by the GeoKit.

First, we should add a new method in the controller location, we define create method to accept
the user input. After that we will
redirect our page to the index method. Our code in the create method looks like:

  def create

    @location = Location.create(params[:location])

    redirect_to :action => "index"

  end

Then we will add the corresponding code in the index
view. When user post the form to location controller,
the
create method will deal with the new location. The supplement code in
the index view looks like:

<h2>Add New Place</h2>

<% form_for :location, :url => { :action => :create } do |f| %>

  <p>Address:

  <%= f.text_field :address %></p>

  <p>Description:

  <%= f.text_field :description %></p>

  <p><%= submit_tag "Add Location" %></p>

<% end %>
 

After the modification, let’s refresh the page, we could
see a new form with input field. Now we add a new location in the field:
333 Post St, San Francisco,
CA
and the description of the
field. Then click Add Location button to post our information. When the page
reloads, we could see a new place marker has been added in our map.

Now click the new marker that we added just
now. We could see a popup window with the description will show up in the map. The
final map looks like the following graph.


 

More information

 You can find additional information about Ruby
support in NetBeans on its wiki page: http://wiki.netbeans.info/wiki/view/Ruby.

Various demos
and tutorials are available from the main Ruby documentation page:
http://www.netbeans.org/kb/60/ruby/index.html.

Finally you can
download the NetBeans IDE for free from the following URL: http://www.netbeans.org/community/releases/60/index.html.
You can either choose to install a small version of the Ruby-only IDE (a
special bundle is provided) or full-blown Java IDE with Ruby support. It is
also possible to add Ruby support to the Java-only IDE using Tools | Plugins.

In the next part
of the series, we will discuss how to add locations in the rails project. As
well as how to show up popup window in our map.

In the meantime,
make sure to try out Ruby support in NetBeans. If you develop in Ruby a lot,
you may find that NetBeans is the IDE you have been looking for!

星期二 四月 01, 2008

Google Maps on Rails with NetBeans(Part One)

Author: Gao Ang

Tutorial Requirements

This tutorial requires the following technology:

  • NetBeans 6.0 Ruby IDE or 6.1 Beta
  • Ruby on Rails: 2.0.2
  • Ruby: 1.8.6
  • Database: MySQL
  • Rails Gems: GeoKit, Cartographer

Objective of our application

Our Google maps Rails mashup demo will accomplish the following tasks:

  1. A table will be created in the database that contents the location description information, such as address, longitude and latitude of the location, description.
  2. There will be a Google Maps with control bar in our browser, as well as a form of us to submit new location.
  3. Users could input specific address location and description, when these information submit by users, location will be translate to the longitude and latitude and store in the backend database.
  4. After user adds a new location, the new point will show up in the map.
  5. If user clicks the new marker, a popup tips will show up with the submitted information.

Okay, let get started to realize these kinds of functions.

Obtaining a Google Maps API Key

The Google Maps API lets us embed Google Maps in our own web pages. First of all, we should have a API key to make use of the Google Maps API. Go to the following address to sign up for the Google Maps API Key http://www.google.com/apis/maps/signup.html. Agree with the terms and conditions of Google Maps usage. Make sure to input the site URL and click "Generate API Key" to obtain the Google Maps API key for our site. Then we should copy the API key generated by Google Maps and we will use it in our configuration file later.

Creating the Ruby on Rails Project

Choose File > New Project in NetBeans. Select Ruby in the Categories field and Ruby on Rails Application in the Projects field and then click Next. Type 'gmaps' in the Project Name field. Choose MySQL as the backend database and then click Finish.


In the Projects window, expand the gmaps node. We could see that all the Rails folder has been generated by NetBeans Ruby IDE.


Then we should create a new database called gmaps_development. We use 'mysqladmin' tools to create this database. In the command line, input the following command:

mysqladmin -u root create gmaps_development

After the database is created, we should expand the 'config' node and add the database description in the database.yml file like this:

development:
adapter: mysql
encoding: utf8
database: gmaps_development
username: root
password:
host: localhost

After the database configuration, we could use the Rake command 'rake db:migrate' to check whether or not our configuration is correct.

Add model for our project

Now, we are gonna add a new model 'location' for our application. In NetBeans Rails Generator, we select 'Generate->model' and input 'location' in the argument and click 'OK'. This action will generate a new model for us.


In the generated database migration file 'db/migrate/001_create_locations.rb', add the following code:

class CreateLocations < ActiveRecord::Migration
def self.up
create_table:locationsdo |t|
t.column:address,:string,:limit =>100
t.column:description,:string,:limit =>100
t.column:lat,:decimal,:precision =>15,:scale =>10
t.column:lng,:decimal,:precision =>15,:scale =>10
end
end

def self.down
drop_table:locations
end

end

In the database migration file, we add three parameters (address, description, latitude, longitude) for our model location. And we also assign the type and precision of these parameters.

Then right click the gmaps project and select 'Migrate Database-> To Current Version' to synchronize the database migration task with the database scheme. We could see the feedback from the console widow like this:

== 1 CreateLocations: migrating =============
-- create_table(:locations)
-> 0.1720s
== 1 CreateLocations: migrated (0.1720s) =======

Then the table locations have been created with the columns address, description, latitude and longitude.

Installing the GeoKit and Cartographer Gem

In the command line of our application folder, input the following command to install the GeoKit gem:

ruby script/plugin install svn://rubyforge.org/var/svn/geokit/trunk

After the installation, we could test the GeoKit first in the Rails console. GeoKit use Google, Yahoo and Geocoder.us for geo-coding (to translate the real address to latitude and longitude). GeoKit should copy your Google Maps API Key to the file config/envirnoment.rb, after the sentence 'GeoKit::Geocoders::google ='. Now, right click gmaps project and then select 'Rails console' to load Rails console in NetBeans. Type in:

>>include GeoKit::Geocoders
>> home = MultiGeocoder.geocode('100 Spear St,
San Francisco, CA')

=> #<GeoKit::GeoLoc:0x 30a 23ac @state="CA", @success=true, @lng=-122.393981, @precision="unknown", @city="San Francisco", @country_code="US", @lat=37.792528,@street_address="", @zip="94105">

We use parameter 'home' to receive the result of real address geo-coding. In the Rails console, we will get the country code, zip code, lng and lat information according to the address '100 Spear St, San Francisco, CA'.

Then we will use the auto coding function of GeoKit to store our address information in the database. In the model app/models/location.rb, add the following sentence:

class Location < ActiveRecord::Base
acts_as_mappable:auto_geocode =>true
end

Now we back to the Rails console, use the following command to create the new record for the location model:

>> Location.create(:address => "")

=> #<Location id: 1, address: "", lat:#<BigDecimal:3063968,'0.37792528E2',12(12)>,lng:#<BigDecimal: 306374c,'-0.122393981E3',12(16)>>

>> Location.create(:address => "")

=> #<Location id: 2, address: "", lat: #<BigDecimal:2fff184,'0.37794391E2',12(12)>, lng: #<BigDecimal:2ffef04,'-0.122394831E3',12(16)>>

Then one record has been added to the Locations table. In the next step, we will use marker to put these record in the locations table.

To make it easy to use Google Maps API in our application, we need another Ruby gem and we should download the Cartographer plugin from the project homepage(http://cartographer.rubyforge.org/) to help us embed Google Maps API in our pages. After download the Cartographer gem, unzip the plugin to the folder vendor/plugins, and move the configuration file cartographer-config.yml to the directory config in the gmaps application.

Of course, we should add the Google API Key to cartographer-config.yml file like this:

127.0.0.1:3000: ABQIAAAAj5cpJ2swzFT77RVZXuP73BTX2XchcwgyHzp4Xo0DHRAzt2aLjhSg2ymVlJvVjBa7kWNgtqU8xxwIAQ

Add controller for our project

Now we will create a controller named 'location'. Open the Rails Generator dialogue and fill the 'Name' field with location and then click 'OK'.


Then the controller file app/controllers/location_controller.rb has been created. There will be two methods in the controller 'index' and 'create', the code of index method looks like:

def index
@locations = Location.find(:all)
@map = Cartographer::Gmap.new("gmaps")
@map.controls = [ :large, :scale ]
@map.debug = true
@map.center = [37.79, -122.4]
@locations.each do |location|

@map.markers << Cartographer::Gmarker.new(:name => "location_" + location.id.to_s, :position => [location.lat, location.lng], :info_window => location.description, :map => @map )

end

end

Here we accomplish there tasks in the index method. First, use 'Location.find(:all)' to get all the records in the database. Second, mark the address to the Maps with Google Maps API. And then put the location information in the Maps with the Google Maps API.

We use the plugin Cartographer to help us to generate the New Maps with Google Maps, the id of the map is gmaps, and this id should be coordinate with the div label in the pages.

Besides, we use Cartographer to define the control bar and the scale bar of the Maps, and use @map.center to set the center position of the map.

Then in the next loop, we get the record from the table and use @map.markers to generate markers of the map. And also display the description sentence in popup windows.

After the index controller, we will focus on the index view and location layout. The location layout (views/layouts/location.rhtml) looks like:

<html>
<
head>
  <title>Map demo</title>
  <%= Cartographer::Header.header_for(request) %>
</
head>
<
body id="map">
   
<div id="main">
     
<%= yield :layout %>
   
</div>
</
body>
</
html>

And the index view (views/location/index.rhtml) looks like:

<h1>Add New Location</h1>
<
hr />
<% @map.zoom = 14 %>
<%
= @map.to_html(true) %>
<
div id="gmaps" style="width: 600px; height: 400px;"></div>

We put Cartographer tag in the head label. Cartographer plugin will interpret our code to Google Maps API JavaScript code to load the Google Maps in the page.

Now let's start the server and open browser to look at what we get from the above code.


We could see a map with two point markers in the final page. These two point markers are the record from the table that we added just now.

More information

You can find additional information about Ruby support in NetBeans on its wiki page: http://wiki.netbeans.info/wiki/view/Ruby.

Various demos and tutorials are available from the main Ruby documentation page: http://www.netbeans.org/kb/60/ruby/index.html.

Finally you can download the NetBeans IDE for free from the following URL: http://www.netbeans.org/community/releases/60/index.html. You can either choose to install a small version of the Ruby-only IDE (a special bundle is provided) or full-blown Java IDE with Ruby support. It is also possible to add Ruby support to the Java-only IDE using Tools | Plugins.

In the next part of the series, we will discuss how to add locations in the rails project. As well as how to show up popup window in our map.

In the meantime, make sure to try out Ruby support in NetBeans. If you develop in Ruby a lot, you may find that NetBeans is the IDE you have been looking for!

About

This is Chinese Functional CA Team Blog. Any suggestion is appreciated.

Search

Archives
« 四月 2014
星期日星期一星期二星期三星期四星期五星期六
  
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
   
       
今天