menambahkan menit pada object tanggal sekarang

Bagaimana menambahkan beberapa menit setelah waktu sekarang (current time) pada Java ?
Misalnya saya ingin menambahkan 20 menit dari waktu sekarang,,

public class Tanggal {
  
  public static void main(String[] args) {
    System.out.println("Tes tanggal ");
    
    Calendar cal =  Calendar.getInstance();
    System.out.println("Waktu " + cal.get(Calendar.HOUR_OF_DAY) +
        ":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
    
    Date tgl = new Date();
    System.out.println("Tanggal = "+tgl);
    tgl = cal.getTime();
    System.out.println("Tanggal 2 = "+tgl);
    
    cal.add(Calendar.MINUTE, 20);
    
    System.out.println("Waktu plus 20 menit " + cal.get(Calendar.HOUR_OF_DAY) +
        ":"+cal.get(Calendar.MINUTE)+":"+cal.get(Calendar.SECOND));
    
    
    
  }

}

== Hasil ===

run:
Tes tanggal
Waktu 10:57:9
Tanggal = Tue Jan 24 10:57:09 CIT 2012
Tanggal 2 = Tue Jan 24 10:57:09 CIT 2012
Waktu plus 20 menit 11:17:9
BUILD SUCCESSFUL (total time: 0 seconds)

Advertisements

Hello Dunia struts 2 netbeans 7.1

Netbeans 7.1

Buat project baru, langkah2nya lihat posting sebelumnya 🙂

1. Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>example/Login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

2.Struts.xml

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <include file="example.xml"/>
    <!-- Configuration for the default package. -->
    <package name="default" extends="struts-default">
    </package>
</struts>

3. example.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <package name="example" namespace="/example" extends="struts-default">
        <action name="HelloWorld" class="example.HelloWorld">
            <result>/example/HelloWorld.jsp</result>
        </action>
        
        <action name="Login" class="example.Login">
            <result name="success">/example/Sukses.jsp</result>
            
            <result name="input">/example/Login.jsp</result>
        </action>
        
    </package>
</struts>


4. Login.jsp

<%-- 
  Document   : Login
  Created on : Jan 13, 2012, 2:35:06 PM
  Author     : root
--%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
  </head>
  <body>
    <h2>Login</h2>
    
    <s:form action="Login">
      <s:actionerror/>
      <s:actionmessage/>
    <table>
        <tr>
          <td><s:textfield name="username" label="Username"/></td>
        </tr>
        <tr>
          <td><s:password name="password" label="Password"/></td>
        </tr>
        <tr>
          <td><s:submit value="Login"/></td>
        </tr>
    </table>
    </s:form>
  </body>
</html>

5. Sukses.jsp

<%-- 
  Document   : Sukses
  Created on : Jan 13, 2012, 2:31:08 PM
  Author     : root
--%>

<%@taglib prefix="s" uri="/struts-tags" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Sukses</title>
  </head>
  <body>
    Hallo <b><s:property value="username"/></b>
    <br/>
    <s:url value="/" var="loginVar"/>
    <s:a href="%{loginVar}">[ Back ]</s:a>
    
  </body>
</html>

6. Login.java

package example;

import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author root
 */
public class Login extends ActionSupport {

  private static final long serialVersionUID = 1L;

  private String username;

  private String password;

  @Override
  public String execute() throws Exception {
     return super.execute();
  }

  @Override
  public void validate() {
    super.validate();

    if (getUsername().equalsIgnoreCase("") || getPassword().equalsIgnoreCase("")){
      addActionError("Username dan Password harus diisi");
    }

    if (!(getUsername().equalsIgnoreCase("admin") && (getPassword().equalsIgnoreCase("adminadmin")))){
      addActionError("Username dan Password tidak cocok");
    }

  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

}

Deploy dalam glassfish 3.1.1

Hasil:
Tampilan Awal

Tampilan Error

Tampilan Sukses

Selesai 🙂

Struts 2 plugin untuk netbeans 7.1

Download netbeans 7.1  http://netbeans.org/

install netbeans 7.1 di ubuntu 10.10

Download strut2 plug in > http://sourceforge.net/projects/struts2nbplugin/files/  (2.9 MB)

Ekstrak file hasil download

Buka netbeans , pada menu Tools > Plugins akan muncul window Plugins , pada tab Download, pilih menu Add Plugin ,, pilih file yang di-ekstrak,, pilih Install

Setelah sukses,, restart netbeans

Buat project stuts 2,, File > New Project

Setting Server

Tambahkan framework struts 2

Klik Finish ,,

met ngoding 🙂