Java Queries Here..

petricnout

Right off the assembly line
Hey Rajkumar.
Myself Petricnout and I read your entire posting. If i have any quiries about java thread, I will definitely paste that quiries here. Visit regularly on this website, give suggestions, give your future preferences, etc. to us. Anyways thanks for posting it .Stay connected.
 

sxyadii

Drifting in DIRT 2
Swing Demo
----------------


Code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

class swingdemo extends Frame implements ActionListener
{
	JFrame frm;
	JMenuBar mb;
	JMenu mFile,mTransaction;
	JMenuItem itmLogin,itmQuitApp,itmCashDeposit,itmChequeDeposit;
	JLabel lblName;
	JTextField txtName;
	public swingdemo()
	{
		frm = new JFrame("Bank Management System");
		frm.setLayout(null);	
		frm.setSize(600,500);
		frm.setVisible(true);

		//Menu Coding
		mb = new JMenuBar();
		mFile = new JMenu("File");
		itmLogin = new JMenuItem("Login");
		itmQuitApp = new JMenuItem("Quit Application");
		mFile.add(itmLogin);
		mFile.add(itmQuitApp);

		mTransaction = new JMenu("Transaction");
		itmCashDeposit = new JMenuItem("Cash Deposit");
		itmChequeDeposit = new JMenuItem("Cheque Deposit");
		mTransaction.add(itmCashDeposit);
		mTransaction.add(itmChequeDeposit);

		itmCashDeposit.addActionListener(this);

		mb.add(mFile);
		mb.add(mTransaction);
		frm.setJMenuBar(mb);

		//Label
		lblName = new JLabel("Name");
		lblName.setBounds(70,20,200,50);
		frm.add(lblName);

		txtName = new JTextField(25);
		txtName.setBounds(140,20,150,20);
		frm.add(txtName);
		
		
	}
	
	public void actionPerformed(ActionEvent e)
	{
		Object o = e.getSource();
		if(o==itmCashDeposit)
		{
			
		}
	}

	public static void main(String args[])
	{

		swingdemo s = new swingdemo();
	}
}
-----------------------------------------
Posted again:
-----------------------------------------
Simple Frame

Code:
import javax.swing.*;

class SimpleFrame extends JFrame
{
	public SimpleFrame()
	{
		this.setSize(200,200);
		this.setLocation(200,200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public void showIt()
	{
		this.setVisible(true);
	}
	
	public void showIt(String title)
	{
		this.setTitle(title);
		this.setVisible(true);
	}
	public void showIt(String title,int x,int y)
	{
		this.setTitle(title);
		this.setLocation(x,y);
		this.setVisible(true);
	}
	public static void main(String args[])
	{
		SimpleFrame f = new SimpleFrame();
		f.showIt();
	}
}
 
Last edited:

layzee

■■■■■■
You cannot have absolute path in your code (ex. D:\xyz). Add the desired directory in the classpath and use the resource (your image in this case) directly without any path references; or have your image file in the same directory (or a sub-directory) as your programs directory and access it accordingly. Moreover, you have to specify the correct resource name including the file extension.

I could make your program work with slight modifications as follows:
Code:
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.awt.Image;

public class Test
{
    public static void main(String[] args) throws Exception
    {
        Test tt = new Test();
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        try
        {
            frame.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(tt.getClass().getResource("icon-mercedes.png")));
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        frame.pack();
        frame.setVisible(true);
    }
}

I had the icon-mercedes.png file in the same directory where the Test.class was.
Hope this helps.

This solution should work fine...
There is no other way I guess than to use the setIconImage function.
To use the icon you must place the image in the same path as that of the class.
 

Nawab

Broken In
look to embed this code in HTML you will have to develop a JSP WebPage instead of HTML, or you could use this as a Servlet for your WebPagic Code Logic
Pls help
I have a java code as follows i would like to embed it in an HTML file can u pls explain how to do.
JAVA code


import java.io.*;
public class angle{
public static void main(String [] args) throws IOException{
BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in));
float a;
double s;
int c;
System.out.println("Hai welcome to the trignometric calculator");
System.out.println("Select from the following options");
System.out.println("1: Sine");
System.out.println("2: Cosine");
System.out.println("3: Tan");
System.out.println("4: Cosine");
System.out.println("5: Cosec");
System.out.println("6: Cot");
System.out.println("Enter an option: ");
System.out.flush();
c=Integer.parseInt (stdin.readLine());

switch ( c ){
case 1 : {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Sine "+a+" = " +(Math.sin(s)));
break;
}
case 2 : {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Cosine "+a+" = " +(Math.cos(s)));
break;
}
case 3 : {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Tan "+a+" = " +(Math.tan(s)));
break;
}
case 4: {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Cosec "+a+" = " +(1/(Math.sin(s))));
break;
}
case 5 : {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Sec "+a+" = " +(1/(Math.cos(s))));
break;
}
case 6 : {
System.out.println("Enter an angle in degrees : ");
a = Float.parseFloat(stdin.readLine());
s = Math.toRadians(a);
System.out.println("Cot "+a+" = " +(1/(Math.tan(s))));
break;
}
default : System.out.println("Ok good bye..............");
break;
}
}
}



Please help me in this matter
 

layzee

■■■■■■
look to embed this code in HTML you will have to develop a JSP WebPage instead of HTML, or you could use this as a Servlet for your WebPagic Code Logic

You can create an applet and embed it in your web page using the APPLET tag
 

alton

Right off the assembly line
can anyone please give me the link to netbeans IDE 6.5 book so that I could easily develop my swing apps rather than coding in Notepad++


For netbeans you should try
netbeans. org as well
java2s. com for java based examples.
 

c2tarun

N3CrO..NiNj@**
Help for my project!!!

hi folks
i want to make a complete windows log recorder in JAVA as my BTech mini project.
The only problem i am facing is how to record clicks and activities on windows using JAVA Listeners.
PLEASE HELP ME OUT!!!!
If possible recommend me any book, or link for theories and concepts.
THANX IN ADVANCE
 

nileshkumar

Right off the assembly line
Need some help here, this is my HTML source-code (this is the code from April-2009 digit fast track)

<html>
<head>
<title>My Favorite Movies</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" language="javaScript">
function addmovie(nameid,listid){
moviename=document.getElementById('nameid').value;
document.getElementById('nameid').value='';
document.getElementById('listid').innerHTML +='<li><a href="#">'+moviename+'</a></li>';
}
</script>
<noscript>
<p> scripting is not supported </p>
</noscript>
</head>
<body>
<h1>A List of my Favorite Movies</h1>
<h2>Movie Series:</h2>
<ul id="sermovies">
<li><a href="#">The Matrix Series</a></li>
<li><a href="#">The Lord of the Rings Series</a></li>
<li><a href="#">Star Wars Series</a></li>
</ul>
<input id="newseries" type="text" />
<input type="button" onclick="addmovie('newseries','sermovies')" value="Add Series"/>
<h2>Individual Movies:</h2>
<ul id="indmovies">
<li><a href="#">Memento</a></li>
<li><a href="#">Batman Begins</a></li>
<li><a href="#">The Dark Knight</a></li>
<li><a href="#">Gattaca</a></li>
<li><a href="#">Shawshank Redemption</a></li>
</ul>
<input id="newmovie" type="text" />
<input type="button" onclick="addmovie('newmovie','indmovies')" value="Add Movie"/>
<p></p>
<div class="footer">
<a href="*www.google.com/">To get your other favorite movies search here </a>
</div>
</body>
</html>

here i am trying add movie name to innetHTML by clicking on button, but that is not happing.
 

prttal

Broken In
I was thinking of creating a new thread for my java problem when I found this. Now can anybody tell me how do I get the mouse pointer's position(x,y) even after it has gone out of the frame. What class does it use? It should be something like this:

import javax.swing.*;

public class abc
{
public static void main(string arg[])
{
JFrame f=new JFrame("Mouse");
JPanel p=new JPanel();
JLabel l=new JLabel(Name_of_variable_storing _the_value of_xy_coordinates_here);
}
}
 

Garbage

God of Mistakes...
hi folks
i want to make a complete windows log recorder in JAVA as my BTech mini project.
The only problem i am facing is how to record clicks and activities on windows using JAVA Listeners.
PLEASE HELP ME OUT!!!!
If possible recommend me any book, or link for theories and concepts.
THANX IN ADVANCE

I was thinking of creating a new thread for my java problem when I found this. Now can anybody tell me how do I get the mouse pointer's position(x,y) even after it has gone out of the frame. What class does it use? It should be something like this:

import javax.swing.*;

public class abc
{
public static void main(string arg[])
{
JFrame f=new JFrame("Mouse");
JPanel p=new JPanel();
JLabel l=new JLabel(Name_of_variable_storing _the_value of_xy_coordinates_here);
}
}

Please have a look at Robot class.
 

gopi_vbboy

Cyborg Agent
i actually want to actually extract data of all results from a webpage

its a php page it ask to enter roll no and i get a result page with Name,Subject and marks

i have to read the contents of the online page and store in file...
in this way i have to do 60 times for all students


how can i automate this task...like i jus give range of roll no ...it shud give a print data collected with the range of result...


thanks in advance

is it possible to do with java

---------- Post added at 03:35 PM ---------- Previous post was at 03:22 PM ----------

---------


one more doubt


how can i distrube a java application i made....do i have to ask the user to everytime run java filename.class everytime?

jar is a solution....but how to make a exe

---------- Post added at 04:53 PM ---------- Previous post was at 03:35 PM ----------

any idea pls?
 
Hi Plasma_Snake,
I am not quite sure about your solution. But i will tell what i think.

File file = new File(args[0]);
Because of this statement u should pass the file name or file name with path during running
i.e,
java FileOps c:\1.txt
u can do it manually by running the same class file at jdk bin folder.It worked for me.
i think there should be some option in netbeans for this. I dont know about it.


or pass a string (file name)as an argument like this
String s1;
read the string (file name)from terminal.
pass it as
File file = new File("s1");
 

gopi_vbboy

Cyborg Agent
i actually want to actually extract data of all results from a webpage

its a php page it ask to enter roll no and i get a result page with Name,Subject and marks

i have to read the contents of the online page and store in file...
in this way i have to do 60 times for all students


how can i automate this task...like i jus give range of roll no ...it shud give a print data collected with the range of result...
 

Garbage

God of Mistakes...
@gopi_vbboy
Its Java queries thread. If you have a problem which needs a PHP solution, please create another thread.
 
OP
furious_gamer

furious_gamer

Excessive happiness
@gopi_vbboy
So that means you can access that page using a Web Service. Does they gave access to that?
Then just use the URL class to pass the input data to that php page and fetch the whole page as the string and parse it. I hope i understand what you said and gave the solution accordingly.
 

gopi_vbboy

Cyborg Agent
the page doesnt support GET method of posting....

---------- Post added at 01:42 PM ---------- Previous post was at 01:40 PM ----------

@gopi_vbboy
Its Java queries thread. If you have a problem which needs a PHP solution, please create another thread.

ok

atleast tell me wat to use to do such web page automation

php or python?

---------- Post added at 01:42 PM ---------- Previous post was at 01:42 PM ----------

also i have to pase a webpage....
 

Garbage

God of Mistakes...
@gopi_vbboy

You can do it in Java too. Use the URL class to make the connection to the URL, pass the data.
Take the response in a String (StringBuffer) and then parse it.
 
Top Bottom