Index
www nie com pl 3
23 (111)
rozdzial 05 (163)
Cizia Zyke Goraczka
abc.com.pl 6
Adam Smith An Inquiry Into The Nature And Causes Of The Wealth Of Nations
Kratochvil Stanisław Psychoterapia kierunki metody badania
wiedza i zycie2
Berling Peter Dzieci graala (2)
25 (192)
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • telenovel.pev.pl

  • [ Pobierz całość w formacie PDF ]
    .It is also possible to create a custom look and feel package, for example, if you are building a framework for a company that wants a distinctive appearance.This is a big job and is far beyond the scope of this book (in fact, you’ll discover it is beyond the scope of many dedicated Swing books!).The clipboardThe JFC supports limited operations with the system clipboard (in theThe following program is a simple demonstration of cut, copy, and paste with String data in a JTextArea.One thing you’ll notice is that the keyboard sequences you normally use for cutting, copying, and pasting also work.But if you look at any JTextField or JTextArea in any other program you’ll find that they also automatically support the clipboard key sequences.This example simply adds programmatic control of the clipboard, and you could use these techniques if you want to capture clipboard text into something other than a JTextComponent.//: c13:CutAndPaste.java// Using the clipboard.import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.datatransfer.*;import com.bruceeckel.swing.*;public class CutAndPaste extends JFrame {JMenuBar mb = new JMenuBar();JMenu edit = new JMenu("Edit");JMenuItemcut = new JMenuItem("Cut"),copy = new JMenuItem("Copy"),paste = new JMenuItem("Paste");JTextArea text = new JTextArea(20, 20);Clipboard clipbd =getToolkit().getSystemClipboard();public CutAndPaste() {cut.addActionListener(new CutL());copy.addActionListener(new CopyL());paste.addActionListener(new PasteL());edit.add(cut);edit.add(copy);edit.add(paste);mb.add(edit);setJMenuBar(mb);getContentPane().add(text);}class CopyL implements ActionListener {public void actionPerformed(ActionEvent e) {String selection = text.getSelectedText();if (selection == null)return;StringSelection clipString =new StringSelection(selection);clipbd.setContents(clipString,clipString);}}class CutL implements ActionListener {public void actionPerformed(ActionEvent e) {String selection = text.getSelectedText();if (selection == null)return;StringSelection clipString =new StringSelection(selection);clipbd.setContents(clipString, clipString);text.replaceRange("",text.getSelectionStart(),text.getSelectionEnd());}}class PasteL implements ActionListener {public void actionPerformed(ActionEvent e) {Transferable clipData =clipbd.getContents(CutAndPaste.this);try {String clipString =(String)clipData.getTransferData(DataFlavor.stringFlavor);text.replaceRange(clipString,text.getSelectionStart(),text.getSelectionEnd());} catch(Exception ex) {System.err.println("Not String flavor");}}}public static void main(String[] args) {Console.run(new CutAndPaste(), 300, 200);}} ///:~The creation and addition of the menu and JTextArea should by now seem a pedestrian activity.What’s different is the creation of the Clipboard field clipbd, which is done through the Toolkit.All the action takes place in the listeners.The CopyL and CutL listeners are the same except for the last line of CutL, which erases the line that’s been copied.The special two lines are the creation of aIn PasteL, data is pulled off the clipboard usingIn the future you can expect more data flavors to be supported.Packagingan applet into a JAR fileJAR files solve the problem by compressing all of your.class files into a single file that is downloaded by the browser.Now you can create the right design without worrying about how many.class files it will generate, and the user will get a much faster download time.Consider TicTacToe.java.It looks like a single class, but in fact it contains five inner classes, so that’s six in all.Once you’ve compiled the program, you package it into a JAR file with the line:jar cf TicTacToe.jar *.classThis assumes that the only.class files in the current directory are the ones from TicTacToe.java (otherwise you’ll get extra baggage).Now you can create an HTML page with the new archive tag to indicate the name of the JAR file.Here is the tag using the old form of the HTML tag, as an illustration:<head><title>TicTacToe Example Applet</title></head><body><applet code=TicTacToe.classarchive=TicTacToe.jarwidth=200 height=100></applet></body>You’ll need to put it into the new (messy, complicated) form shown earlier in the chapter in order to get it to work.ProgrammingtechniquesBecause GUI programming in Java has been an evolving technology with some very significant changes between Java 1.0/1.1 and the Swing library in Java 2, there have been some old programming idioms that have seeped through to examples that you might see given for Swing.In addition, Swing allows you to program in more and better ways than were allowed by the old models.In this section, some of these issues will be demonstrated by introducing and examining some programming idioms.Binding eventsdynamicallyOne of the benefits of the Swing event model is flexibility.You can add and remove event behavior with single method calls.The following example demonstrates this://: c13:DynamicEvents.java// You can change event behavior dynamically.// Also shows multiple actions for an event.// <applet code=DynamicEvents// width=250 height=400></applet>import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.util.*;import com.bruceeckel.swing.*;public class DynamicEvents extends JApplet {ArrayList v = new ArrayList();int i = 0;JButtonb1 = new JButton("Button1"),b2 = new JButton("Button2");JTextArea txt = new JTextArea();class B implements ActionListener {public void actionPerformed(ActionEvent e) {txt.append("A button was pressed\n");}}class CountListener implements ActionListener {int index;public CountListener(int i) { index = i; }public void actionPerformed(ActionEvent e) {txt.append("Counted Listener "+index+"\n");}}class B1 implements ActionListener {public void actionPerformed(ActionEvent e) {txt.append("Button 1 pressed\n");ActionListener a = new CountListener(i++);v.add(a);b2.addActionListener(a);}}class B2 implements ActionListener {public void actionPerformed(ActionEvent e) {txt.append("Button2 pressed\n");int end = v.size() - 1;if(end >= 0) {b2.removeActionListener((ActionListener)v.get(end));v.remove(end);}}}public void init() {Container cp = getContentPane();b1.addActionListener(new B());b1.addActionListener(new B1());b2.addActionListener(new B());b2.addActionListener(new B2());JPanel p = new JPanel();p.add(b1);p.add(b2);cp.add(BorderLayout.NORTH, p);cp.add(new JScrollPane(txt));}public static void main(String[] args) {Console.run(new DynamicEvents(), 250, 400);}} ///:~The new twists in this example are:lThereis more than one listener attached to each Button [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • aceton.keep.pl
  • 
    Wszelkie Prawa Zastrzeżone! Kawa była słaba i bez smaku. Nie miała treści, a jedynie formę. Design by SZABLONY.maniak.pl.