Presentation is loading. Please wait.

Presentation is loading. Please wait.

It attached with method ,class and interface etc…

Similar presentations


Presentation on theme: "It attached with method ,class and interface etc…"— Presentation transcript:

1 It attached with method ,class and interface etc…
Annotations in java It provides additional information and that can be used by JVM and Java Compiler It attached with method ,class and interface etc… Type 1. Built-in annotation 2.Custom annotation

2 Built –in annotation 1.Used in java code 2. Used in other annotation

3 Built-in (cont..) @override : =========== It assures that method of subclass overriding method of super class Class cse{ void get() { s.o.p(“srm”); } Class ece extends Void get() s.o.p(“vit”);

4 Cont.. @Suppresswarning =========================== Class cse “) PSVM(string arg[]) Stack st=new stack (); St.push(10); St.push(20); }

5 Cont.. @deprecated ========== Class cse { Void get1() s.o.p(“hai”); } Void get2() s.o.p(“hi”);

6 Custom annotation It allows user to create annotation . It start . Type: 1.Marker annotation 2.Single value 3.Multivalue

7 Cont.. 1.Marker annotation:(no user{} ================== 2. Single value(only one user{ Int t() default 0; } ============= user { Int t1(); Int t2();

8 Cont.. @target =========
it is used to specify at which type, the annotation is used. The java.lang.annotation.ElementType enum declares many constants to specify the type of element where annotation is to be applied such as TYPE, METHOD, FIELD etc..

9 Cont.. @Retention ===============
@Retention annotation is used to specify to what level annotation will be available. Whether compiler level or JVM level

10 Cont.. @Inherited ===========
annotations are not inherited automatically to subclasses. annotation marks the annotation to be inherited to subclasses. Example @inherited class super {} Class derive extends super{}

11 Cont.. import java.lang.annotation.*; @interface user{ int count(); } //Applying annotation class public void get(){ System.out.println(“srm"); } } //Accessing annotation class customclass{ public static void main(String args[])throws Exception { H h=new H(); Method m=h.getClass().getMethod(“get"); user ob=m.getAnnotation(user.class); System.out.println("value is: "+ob.count()); }}

12 Java Swing Swing API is a set of extensible GUI Components that used to create JAVA based Front End/GUI Applications. MVC M-Model represents data from view V-View represents visual representation of the component's data. C-Controller gets input from user and perform manipulation on that data.

13 JFRAME import javax.swing.*; public class FirstSwingExample { public static void main(String[] args) { JFrame f=new JFrame(); //creating instance of JFrame JButton b=new JButton("click"); //creating instance of JButton b.setBounds(130,100,100, 40); f.add(b);//adding button in JFrame f.setSize(400,500); f.setLayout(null); f.setVisible(true); } }

14 JDialog It is used to create small dialog window
JFrame f= new JFrame();           d = new JDialog(f , "Dialog Example", true);  

15 Jpanel It provides space for placing components.
  JPanel panel=new JPanel();           panel.setBounds(40,80,200,200);          panel.setBackground(Color.gray);  

16 Jrootpane public class RootExample2 {   public static void main(String[] args) {     JFrame f = new JFrame();     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     JRootPane root = f.getRootPane();     // Create a menu bar     JMenuBar bar = new JMenuBar();     JMenu menu = new JMenu("File");     bar.add(menu);     menu.add("Open");     menu.add("Close");     root.setJMenuBar(bar);     // Add a button to the content pane     root.getContentPane().add(new JButton("Hello World"));     // Display the UI     f.pack();     f.setVisible(true);   } }

17 JlayerdPane JLayeredPane lp = getLayeredPane(); // Create 3 buttons JButton top = new JButton(); top.setBackground(Color.white); top.setBounds(20, 20, 50, 50); JButton middle = new JButton(); middle.setBackground(Color.gray); middle.setBounds(40, 40, 50, 50); JButton bottom = new JButton(); bottom.setBackground(Color.black); bottom.setBounds(60, 60, 50, 50); // Place the buttons in different layers lp.add(middle, new Integer(2)); lp.add(top, new Integer(3)); lp.add(bottom, new Integer(1));

18 Swing –Components Jbutton : ================= JFrame f=new JFrame("Button Example"); JButton b=new JButton("Click Here"); b.setBounds(50,100,95,30); f.add(b); f.setSize(400,400); f.setLayout(null); f.setVisible(true);

19 Cont.. Jlable: JFrame f= new JFrame("Label Example"); JLabel l1,l2; l1=new JLabel("First Label."); l1.setBounds(50,50, 100,30); l2=new JLabel("Second Label."); l2.setBounds(50,100, 100,30); f.add(l1); f.add(l2); f.setSize(300,300);

20 Cont.. JTextField: JFrame f= new JFrame("TextField Example"); JTextField t1,t2; t1=new JTextField("Welcome to Javatpoint."); t1.setBounds(50,100, 200,30); t2=new JTextField("AWT Tutorial"); t2.setBounds(50,150, 200,30); f.add(t1); f.add(t2); f.setSize(400,400);

21 Cont.. JComboBox: f=new JFrame("ComboBox Example"); String country[]={"India","Aus","U.S.A","England","Newzealand"}; JComboBox cb=new JComboBox(country); cb.setBounds(50, 50,90,20); f.add(cb);

22 Cont.. Jlist ===================== JFrame f= new JFrame(); DefaultListModel<String> l1 = new DefaultListModel<>(); l1.addElement("Item1"); l1.addElement("Item2"); l1.addElement("Item3"); l1.addElement("Item4"); JList<String> list = new JList<>(l1); list.setBounds(100,100, 75,75); f.add(list);

23 Cont.. Jtable: =============== f=new JFrame(); String data[][]={ {"101","Amit","670000"}, {"102","Jai","780000"}, {"101","Sachin","700000"}}; String column[]={"ID","NAME","SALARY"}; JTable jt=new JTable(data,column);

24 Cont.. JTabbedPane: f=new JFrame(); JTextArea ta=new JTextArea(200,200); JPanel p1=new JPanel(); p1.add(ta); JPanel p2=new JPanel(); JPanel p3=new JPanel(); JTabbedPane tp=new JTabbedPane(); tp.setBounds(50,50,200,200); tp.add("main",p1); tp.add("visit",p2); tp.add("help",p3); f.add(tp);

25 Event handling ActionEvent ---- ActionListener MouseEvent---- MouseListener and MouseMotionListener MouseWheel EventMouseWheelListener KeyEvent KeyListener ItemEvent ItemListener

26 Event Methods Button MenuItem TextField TextArea Checkbox Choice List
public void addActionListener(ActionListener a){} MenuItem TextField public void addTextListener(TextListener a){} TextArea Checkbox public void addItemListener(ItemListener a){} Choice List

27 Example for event import java.awt.*; import java.awt.event.*;
class AEvent extends Frame implements ActionListener{   TextField tf;   AEvent(){      //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 AEvent();  


Download ppt "It attached with method ,class and interface etc…"

Similar presentations


Ads by Google