Programming.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Programming CS422 1 FLTK: Fast Light Toolkit • http://www.fltk.org • FLTK is a cross-platform C++ GUI toolkit for UNIX®/ Linux® (X11), Microsoft® Windows®, and MacOS® X • FLTK provides modern GUI functionality without the bloat and supports 3D graphics via OpenGL® and its built-in GLUT emulation. • FLTK is designed to be small and modular enough to be statically linked, but works fine as a shared library. • FLTK also includes an UI builder called FLUID that can be used to create applications 2 FLTK 3 Program #include <FL/Fl.H> #include <FL/Fl_Window.H> #include <FL/Fl_Box.H> CXXFLAGS=`fltk-config --cxxflags` LDLIBS=`fltk-config --ldflags` int main(int argc, char **argv) { Fl_Window *window = new Fl_Window(300,180); Fl_Box *box = new Fl_Box(20,40,260,100,"Hello, World!"); box->box(FL_UP_BOX); box->labelsize(36); box->labelfont(FL_BOLD+FL_ITALIC); box->labeltype(FL_SHADOW_LABEL); window->end(); window->show(argc, argv); return Fl::run(); } 4 Swing • Java language • JFC is short for Java Foundation Classes, which encompass a group of features for building graphical user interfaces (GUIs) and adding rich graphics functionality and interactivity to Java applications. It is defined as containing the features shown in the table below • Swing GUI, Look-and-Feel, Accessibility API, Java 2D API, Drag-and-Drop Support, Internationalization, ... 5 Swing import javax.swing.*; public class HelloWorldSwing { private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. Run: JFrame frame = new JFrame("HelloWorldSwing"); javac SwingApplication.java java SwingApplication frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. JLabel label = new JLabel("Hello World"); public static void main(String[] args) { frame.getContentPane().add(label); javax.swing.SwingUtilities.invokeLater(new Runnable() { //Display the window. public void run() { frame.pack(); createAndShowGUI(); frame.setVisible(true); } }); } } } 6 wxWidgets • wxWidgets lets developers create applications for Win32, Mac OS X, GTK+, X11, Motif, WinCE, and more using one codebase • It can be used from languages such as C++, Python, Perl, and C#/.NET • wxWidgets applications look and feel native. This is because wxWidgets uses the platform's own native controls rather than emulating them • It's also extensive, free, open-source, and matures • http://wxwidgets.org/ 7 C++ bool MyApp::OnInit() #include "wx/wx.h" { MyFrame *frame = new MyFrame( "Hello World", ...); class MyApp: public wxApp frame->Show(TRUE); { SetTopWindow(frame); virtual bool OnInit(); return TRUE; }; } class MyFrame: public wxFrame MyFrame::MyFrame(const wxString& title, ...) { { public: wxMenu *menuFile = new wxMenu; MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); menuFile->Append( ID_About, "&About..." ); menuFile->AppendSeparator(); void OnQuit(wxCommandEvent& event); menuFile->Append( ID_Quit, "E&xit" ); void OnAbout(wxCommandEvent& event); wxMenuBar *menuBar = new wxMenuBar; menuBar->Append( menuFile, "&File" ); DECLARE_EVENT_TABLE() SetMenuBar( menuBar ); }; CreateStatusBar(); SetStatusText( "Welcome to wxWindows!" ); enum } { ID_Quit = 1, ID_About, void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) }; { Close(TRUE); BEGIN_EVENT_TABLE(MyFrame, wxFrame) } EVT_MENU(ID_Quit, MyFrame::OnQuit) EVT_MENU(ID_About, MyFrame::OnAbout) void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) END_EVENT_TABLE() { wxMessageBox("This is a wxWindows Hello world sample", IMPLEMENT_APP(MyApp) "About Hello World", wxOK | wxICON_INFORMATION, this); } 8 C++ • CXXFLAGS=`wx-config --cxxflags` • LDFLAGS=`wx-config --libs` 9 Python import wx class MyApp(wx.App): ID_ABOUT = 101 def OnInit(self): ID_EXIT = 102 frame = MyFrame(None, -1, "Hello from wxPython") frame.Show(True) class MyFrame(wx.Frame): self.SetTopWindow(frame) def __init__(self, parent, ID, title): return True wx.Frame.__init__(self, parent, ID, title, wx.DefaultPosition, wx.Size(200, 150)) app = MyApp self.CreateStatusBar() self.SetStatusText("This is the statusbar") menu = wx.Menu() menu.Append(ID_ABOUT, "&About", Run: "More information about this program") python app.py menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the program") menuBar = wx.MenuBar() menuBar.Append(menu, "&File"); self.SetMenuBar(menuBar) 10 Qt • Qt sets the standard for high-performance, cross- platform application development • It includes a C++ class library and tools for cross- platform development and internationalization • Native looks • Open Source and commercial licenses • Linux, Mac, Win, embedded OS, ... • http://www.trolltech.com/products/qt/ 11 Applications • K Desktop Environment • Photoshop Elements • Google Earth 12 Qt #include <qapplication.h> Compile #include <qpushbutton.h> • • pkg-config --libs qt-mt pkg-config --cflags qt-mt int main( int argc, char **argv ) • { QApplication a( argc, argv ); QPushButton hello( "Hello world!", 0 ); hello.resize( 100, 30 ); a.setMainWidget( &hello ); hello.show(); return a.exec(); } 13.