Search This Blog

Wednesday, 2 September 2015

Paint Crosshair line drawing tool in Java

package rehan;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;

import javax.swing.JFrame;

public class DefPoly extends JFrame{

ArrayList<Point> pointsArrayList = new ArrayList<Point>();

public DefPoly(){
setVisible(true);
setSize(500,500);
addWindowListener(new WindowListener() {

@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void windowClosing(WindowEvent arg0) {
System.exit(0);

}

@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub

}

@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub

}
});
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent evt){
pointsArrayList.add( evt.getPoint() );
repaint();
}
});
setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
}

public static void main(String[] args) {
new DefPoly();
}

public void paint(Graphics g){
g.setColor(Color.white);
if (pointsArrayList.size()>=2){
for (int i = 0; i<pointsArrayList.size()-1; i++){
Point p1 = pointsArrayList.get(i);
Point p2 = pointsArrayList.get(i+1);
g.drawLine(p1.x, p1.y, p2.x, p2.y);
}
}
}

}

Thursday, 25 June 2015

How pinch zoom image in image zoom android?

http://stackoverflow.com/questions/16894215/how-pinch-zoom-image-in-image-zoom-android

Tuesday, 23 June 2015

browse button android

http://stackoverflow.com/questions/21072034/image-browse-button-in-android-activity

Saturday, 16 May 2015

Send Mail ASP.NET

ASP.NET HTML CoDE:

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">
    <p>
        Please Fill the Following to Send Mail.</p>
    <p>
        Your name:
        <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="*"
            ControlToValidate="YourName" ValidationGroup="save" /><br />
        <asp:TextBox ID="YourName" runat="server" Width="250px" /><br />
        Your email address:
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
            ControlToValidate="YourEmail" ValidationGroup="save" /><br />
        <asp:TextBox ID="YourEmail" runat="server" Width="250px" />
        <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator23"
            SetFocusOnError="true" Text="Example: username@gmail.com" ControlToValidate="YourEmail"
            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic"
            ValidationGroup="save" /><br />
        Subject:
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*"
            ControlToValidate="YourSubject" ValidationGroup="save" /><br />
        <asp:TextBox ID="YourSubject" runat="server" Width="400px" /><br />
        Your Question:
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*"
            ControlToValidate="Comments" ValidationGroup="save" /><br />
        <asp:TextBox ID="Comments" runat="server" 
                TextMode="MultiLine" Rows="10" Width="400px" />
    </p>
    <p>
        <asp:Button ID="btnSubmit" runat="server" Text="Send" 
                    OnClick="Button1_Click" ValidationGroup="save" />
    </p>
</asp:Panel>
<p>
    <asp:Label ID="DisplayMessage" runat="server" Visible="false" />
</p>  


Code behind File:

protected void SendMail()
{
    // Gmail Address from where you send the mail
    var fromAddress = "Gmail@gmail.com";
    // any address where the email will be sending
    var toAddress = YourEmail.Text.ToString(); 
    //Password of your gmail address
    const string fromPassword = "Password";
     // Passing the values and make a email formate to display
    string subject = YourSubject.Text.ToString();
    string body = "From: " + YourName.Text + "\n";
    body += "Email: " + YourEmail.Text + "\n";
    body += "Subject: " + YourSubject.Text + "\n";
    body += "Question: \n" + Comments.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
    {
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    }
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
}

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        //here on button click what will done 
        SendMail();
        DisplayMessage.Text = "Your Comments after sending the mail";
        DisplayMessage.Visible = true;
        YourSubject.Text = "";
        YourEmail.Text = "";
        YourName.Text = "";
        Comments.Text = "";
    }
    catch (Exception) { }
}

Wednesday, 21 January 2015

Add button using code dynamically in android

How to Add button using code dynamically in android

Main.xml

<LinearLayout
        android:id="@+id/LinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

</LinearLayout>


Main.java


LinearLayout myLayout = (LinearLayout) findViewById(R.id.LinearLayout1);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
myLayout.setOrientation(LinearLayout.VERTICAL);
  
Button button = new Button(this);
button.setText("B1");
myLayout.addView(button, params);

Friday, 2 January 2015

How to check Wifi State (On or off) - Android

Add this line to AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


Main.java


ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

boolean isWifiConnected = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();

if (isWifiConnected) // true if wifi connected
editText.setText("Wifi is connected");
else
editText.setText("Wifi is NOT connected");

ListView - Get data from xml - Android

Main.xml

<ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>


Main.java


ListView listView = (ListView) findViewById(R.id.listView1);
listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.countries)));