package pages; import javax.swing.*;import java.awt.*; public class page396 extends JFrame{ public page396(){ setTitle("Label example"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container c = getContentPane(); c.setLayout(new FlowLayout()); JLabel textLabel = new JLabel("I am James Gosling"); ImageIcon img = new ImageIcon("C:\\Users\\hm970\\IdeaProjects\\BjavaSwingPrac" + "\\src\\pages\\imgs\\gosling.png"); JLabel imageLabel = new JLabel(img); ImageIcon icon = new ImageIcon("C:\\Users\\hm970\\IdeaProjects\\BjavaSwingPrac" + "\\src\\pages\\imgs\\phone.png"); JLabel label = new JLabel("Would you like to have a coffee?" + " just call me", icon, SwingConstants.CENTER ); c.add(textLabel); c.add(imageLabel); c.add(label); setSize(300,500); setVisible(true); } public static void main(String[] args){ new page396();} }
<HTML> <body> </body> <script> function Calculator() { let methods = { "-" : (a, b) => a - b, "+" : (a, b) => a + b }; //methods is an object which keeps key for operators //and value to return the actual operation values //each returns the result of operation that key(operator) does this.calculate = function (str){ //calculate is one element in the function Calculator //it takes the string and returns the value //in the function element list is delimeted by , not ; let split = str.split(" "), a = +split[0], op = split[1], b = split [2] if(!methods[op] || isNaN(a) || isNaN(b)) { return NaN; // error handling } return methods[op](a,b); } this.addMethod = function(name, func){ methods[name] = func; //this is how to add new key and ele to object } } let powerCalc = new Calculator; powerCalc.addMethod("*&
댓글
댓글 쓰기