Wednesday, April 24, 2019
multilevel interface
interface A
{
void input();
}
interface B extends A
{
public void output();
}
class cl implements B
{
int a,b;
public void input()
{
a=2;
b=3;}
public void output()
{
int sum;
sum=a+b;
System.out.println(sum);
}
}
public class diya1
{
public static void main(String args[])
{
cl ob=new cl();
ob.input();
ob.output();
}}
D:\>javac diya1.java
D:\>java diya1
5
D:\>
edited by diya
edited by diya
multiple inheritence
interface A
{
void input();
}
interface B
{
public void output();
}
class cl implements A,B
{
int a,b;
public void input()
{
a=2;
b=3;}
public void output()
{
int sum;
sum=a+b;
System.out.println(sum);
}
}
public class diya1
{
public static void main(String args[])
{
cl ob=new cl();
ob.input();
ob.output();
}
}
D:\>javac diya1.java
D:\>java diya1
5
D:\>
edited by diyaone level interface
interface A
{
void input();
void sum();
}
class cl implements A
{
int a,b;
public void input()
{
a=2;
b=3;
}
public void sum()
{
int c;
c=a+b;
System.out.println(c);
}
}
public class p2
{
public static void main(String args[])
{
cl ob=new cl();
ob.input();
ob.sum();
}
}
Output::
D:\>javac p2.java
D:\>java p2
5
D:\>javac diya1.java
edited by diyaTuesday, April 23, 2019
basics of event handling
1. label:
l=new Label();
l.setText("string");
2. textbox:
TextField tf;
String s=tf.getText();
tf3.setText(text);
3. text area:
area=new TextArea();
String text=area.getText();
textArea = new TextArea(2, 10);
textArea.setSize(300, 100);
textArea.setText("123456 789123");
4. checkbox:
Checkbox checkbox2 = new Checkbox("Java", true);
5. checkbox group :
CheckboxGroup cbg = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("C++", cbg, false); Checkbox checkBox2 = new Checkbox("Java", cbg, false);
6. list box:
Choice c=new Choice();
c.setBounds(100,100, 75,75);
c.add("Item 1");
c.add("Item 2");
c.add("Item 3");
c.add("Item 4");
c.add("Item 5");
print string using textbox and commandbutton (method 2)
import java.awt.*;
import java.awt.event.*;
class p1 extends Frame implements ActionListener{
TextField tf;
p1(){
//create components
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
//register listener
b.addActionListener(this);//passing current instance
//add components and set size, layout and visibility
add(b);add(tf);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
public static void main(String args[]){
new p1();
}
}
output::
reference -- javapoint.com
import java.awt.event.*;
class p1 extends Frame implements ActionListener{
TextField tf;
p1(){
//create components
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
//register listener
b.addActionListener(this);//passing current instance
//add components and set size, layout and visibility
add(b);add(tf);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
public static void main(String args[]){
new p1();
}
}
output::
reference -- javapoint.com
- Button
- public void addActionListener(ActionListener a){}
- MenuItem
- public void addActionListener(ActionListener a){}
- TextField
- public void addActionListener(ActionListener a){}
- public void addTextListener(TextListener a){}
- TextArea
- public void addTextListener(TextListener a){}
- Checkbox
- public void addItemListener(ItemListener a){}
- Choice
- public void addItemListener(ItemListener a){}
- List
- public void addActionListener(ActionListener a){}
- public void addItemListener(ItemListener a){}
reference -- javapoint.com
print string using text box and command buttton
import java.awt.*;
import java.awt.event.*;
public class p1 {
public static void main(String[] args)
{
Frame f=new Frame("Button Example");
final TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new Button("Click Here");
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tf.setText("this is a text box");
}
}
);
f.add(b);f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
output:::
import java.awt.event.*;
public class p1 {
public static void main(String[] args)
{
Frame f=new Frame("Button Example");
final TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new Button("Click Here");
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
tf.setText("this is a text box");
}
}
);
f.add(b);f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
output:::
Friday, April 12, 2019
Subscribe to:
Posts (Atom)