Differences

This shows you the differences between two versions of the page.

Link to this comparison view

poo:breviare:breviar-10 [2018/11/27 17:05]
matei.teodorescu
poo:breviare:breviar-10 [2020/12/10 13:47] (current)
carmen.odubasteanu
Line 1: Line 1:
 ====== Breviar ====== ====== Breviar ======
-===== Laborator 10 - Interfete =====+===== Laborator 10 - Interfete ​grafice ​=====
  
   * Responsabil:​ [[mihai.nan.cti@gmail.com|Mihai Nan]]   * Responsabil:​ [[mihai.nan.cti@gmail.com|Mihai Nan]]
Line 40: Line 40:
         super(text);​         super(text);​
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);​         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);​
-        setMinimumSize(new Dimension (3 0 02 0 0));+        setMinimumSize(new Dimension (300200));
         getContentPane().setBackground (Color.blue);​         getContentPane().setBackground (Color.blue);​
         setLayout(new SpringLayout());​         setLayout(new SpringLayout());​
Line 79: Line 79:
         super(text);​         super(text);​
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);​         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);​
-        setMinimumSize(new Dimension(3 0 02 0 0));+        setMinimumSize(new Dimension(300200));
         getContentPane().setBackground(Color.blue);​         getContentPane().setBackground(Color.blue);​
         setLayout(new SpringLayout());​         setLayout(new SpringLayout());​
Line 95: Line 95:
    ​@Override    ​@Override
    ​public void actionPerformed(ActionEvent e){    ​public void actionPerformed(ActionEvent e){
-       JButton button = (JButton)e.getSource();​ +    
-       ​if (button.getText().equals("​Apasa"​)){+   /​* ​   
 +    ​JButton button = (JButton)e.getSource();​ 
 +    if (button.getText().equals("​Apasa"​)) ​// valabil daca aveam mai multe butoane ascultate de acest ascultator 
 +    */
        ​System.out.println("​Butonul a fost apasat ! " ) ;        ​System.out.println("​Butonul a fost apasat ! " ) ;
-       } 
    }    }
 } }
Line 110: Line 112:
 <code java> <code java>
  
-c l a s s Text e x t e n d s JFrame implements ​A c ti o n Li s t e n e r +class Text extends ​JFrame implements ​ActionListener
-2 p r i v a t e JButton button ; +    ​private ​JButton button; 
-3 p r i v a t e JTe x tField u s e r +    ​private JTextField user
-4 p r i v a t e JP a s sw o rdField p a s s +    ​private JPasswordField pass
-5 + 
-6 p u bli c Text ( S t ri n g t e x t ) { +    ​public ​Text (String text){ 
-7 supe r t e x t ) ; +        super(text); 
-8 s e t D e f a ul t Cl o s eO p e r a ti o n ( JFrame .EXIT_ON_CLOSE) ; +        ​setDefaultCloseOperation ​(JFrame.EXIT_ON_CLOSE);​ 
-setMinimumSize (new Dimension ( 3 0 0 2 0 0 ) ) ; +        setMinimumSize(new Dimension(300200)); 
-10 getContentPane ( ) . setBackground ( C ol o r bl u e ) ; +        getContentPane().setBackground(Color.blue); 
-11 se tL a y ou t (new FlowLayout ( ) ) ; +        ​setLayout(new FlowLayout());​ 
-12 button = new JButton ( " Apasa " ) ; +        button = new JButton ("​Apasa"​);​ 
-13 button . a d dA c ti o nLi s t e n e r t h i s ) ; +        button.addActionListener(this); 
-14 add ( button ) ; +        add(button);​ 
-15 u s e r = new JTe x tField ​1 5 ) ; +        ​user ​= new JTextField(15); 
-16 add ( u s e r ) ; +        add(user); 
-17 p a s s = new JP a s sw o rdField ​1 5 ) ; +        ​pass ​= new JPasswordField(15); 
-18 add ( p a s s ) ; +        add(pass); 
-19 show ( ) ; +        show(); 
-20 pack ( ) ; +        pack(); 
-21 +    
-22 + 
-23 p u bli c s t a t i c v oid main ( S t ri n g a r g s [ ] ) { +    ​public static void main (String args[]){  
-24 Text b = new Text ( " ​L ab o r a t o r POO" ) ; +        Text b = new Text ("LaboratorPOO"); 
-25 +    
-26 + 
-27 @Override +    @Override 
-28 p u bli c v oid a c ti o nP e r f o rm e d ( ActionEvent e ) { +    ​public void actionPerformed(ActionEvent e){ 
-29 JButton button = ( JButton ) e . g e t S o u r c e ( ) ; +        /​* ​   
-30 i f ( button . ge tTex t ( ) . e q u al s ( " Apasa " ) ) { +        ​JButton button = (JButton)e.getSource(); 
-31 System . out . p r i n t l n u s e r ge tTex t ( )+p a s s ge tTex t ( ) ) ; +        ​if ​(button.getText().equals("​Apasa"​)) ​// valabil daca aveam mai multe butoane ascultate de acest ascultator 
-32 } +       */ 
-33 +        System.out.println(user.getText() + pass.getText()); 
-34 }+    
 +}
  
 </​code>​ </​code>​
Line 167: Line 170:
 <code java> <code java>
  
-c l a s s Text e x t e n d s JFrame { +class Text extends ​JFrame{ 
-2 p r i v a t e JTextArea ​te x tA re a +    ​private ​JTextArea ​textArea  
-3 p r i v a t e J S c r oll P a n e s c r o l l +    ​private JScrollPane scroll
-4 + 
-5 p u bli c Text ( S t ri n g t e x t ) { +    ​public ​Text (String text){ 
-6 supe r t e x t ) ; +        super(text); 
-7 s e t D e f a ul t Cl o s eO p e r a ti o n ( JFrame .EXIT_ON_CLOSE) ; +        ​setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);​ 
-setMinimumSize (new Dimension ( 3 0 0 2 0 0 ) ) ; +        setMinimumSize(new Dimension(300200)); 
-getContentPane ( ) . setBackground ( C ol o r bl u e ) ; +        getContentPane().setBackground(Color.blue); 
-10 se tL a y ou t (new FlowLayout ( ) ) ; +        ​setLayout(new FlowLayout());​ 
-11 te x tA re a = new JTextArea ( 2 0 0 1 0 0 ) ; +        ​textArea ​= new JTextArea(200100); 
-12 te x tA re a . setLineWrap ( t r u e ) ; +        ​textArea.setLineWrap(true); 
-13 te x tA re a . setWrapStyleWord ( t r u e ) ; +        ​textArea.setWrapStyleWord(true); 
-14 te x tA re a se tF on t (new Font ( "​Tahoma"​ , 2 , 1 2 ) ) ; +        ​textArea.setFont(new Font("​Tahoma",​ 2, 1 2)); 
-15 s c r o l l = new J S c r oll P a n e te x tA re a ) ; +        ​scroll ​= new JScrollPane(textArea); 
-16 add ( s c r o l l ) ; +        add(scroll); 
-17 show ( ) ; +        show(); 
-18 pack ( ) ; +        pack(); 
-19 +    
-20 + 
-21 p u bli c s t a t i c v oid main ( S t ri n g a r g s [ ] ) { +     public static void main (String args[]) { 
-22 Text b = new Text ( " ​L ab o r a t o r POO" ) ; +        Text b = new Text("LaboratorPOO"); 
-23 +    
-24 }+}
  
 </​code>​ </​code>​
poo/breviare/breviar-10.1543331111.txt.gz · Last modified: 2018/11/27 17:05 by matei.teodorescu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0