0
votes

the img is clicked from the camera (the code below) but the problem is how to show them in list from gui renderer..

@Override
    protected void onListFromCamera_SaveImgAction(final Component c, ActionEvent event) {
        Capture.capturePhoto(new ActionListener() {

            public void actionPerformed(ActionEvent evt) {
                try {
                    if (evt == null) {
                        return;
                    }

                    String path = (String) evt.getSource();
                    if (ImageIO.getImageIO() != null) {
                        String photoName = "" + System.currentTimeMillis();
                        java.io.OutputStream os = Storage.getInstance().createOutputStream(photoName);
                        ImageIO.getImageIO().save(FileSystemStorage.getInstance().openInputStream(path), os, ImageIO.FORMAT_JPEG, 50, 50, 0.9f);
                        os.close();
                        Image img = Image.createImage(Storage.getInstance().createInputStream(photoName));
                        photo = photoName;
//                        ((Label)c).setIcon(img);
                        findLabelImg().setIcon(img);
                        c.getParent().getParent().animateLayout(400);
 }
                } catch (Exception e) {
                }
            }
        });
    }

//the images captured to be listed in the listModel method below... this is the problem i have

@Override
    protected boolean initListModelCapturedList(final List cmp) {
        cmp.setModel(new com.codename1.ui.list.DefaultListModel(new String[]{"Item 1", "Item 2", "Item 3"}));

        final Button b = ((GenericListCellRenderer) cmp.getRenderer()).extractLastClickedComponent();

        final Button mybtn = findBtncamera();
        System.out.println("sdkfjdkfj" + b);

        if (b != null && "btncamera".equals(b.getName())) {//btncamera is the name of the button in renderer
            mybtn.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent evt) {
                     //do smth
                     showForm("Main", null);
                   }
               });
1

1 Answers

0
votes

You can check out this tutorial covering capture and adding to a grid of images: https://www.udemy.com/build-mobile-ios-apps-in-java-using-codename-one/

It also uses the ImageViewer class to allow you to swipe thru images.